diff options
| author | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-06 23:41:34 -0700 |
|---|---|---|
| committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-06 23:41:34 -0700 |
| commit | fbc7a328016af60052dd3f33c2d906e6c6447a5f (patch) | |
| tree | f7b5e4cf40a72a0024079ec7628bbe70a6a019b9 /src/client/views/nodes/DocumentLinksButton.tsx | |
| parent | 2e1284512f6f302673874ef3c368bdc50735f2a6 (diff) | |
set up linking for hypothesis annotations
Diffstat (limited to 'src/client/views/nodes/DocumentLinksButton.tsx')
| -rw-r--r-- | src/client/views/nodes/DocumentLinksButton.tsx | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx index 37d47700f..f12472b01 100644 --- a/src/client/views/nodes/DocumentLinksButton.tsx +++ b/src/client/views/nodes/DocumentLinksButton.tsx @@ -7,12 +7,13 @@ import { UndoManager } from "../../util/UndoManager"; import './DocumentLinksButton.scss'; import { DocumentView } from "./DocumentView"; import React = require("react"); -import { DocUtils } from "../../documents/Documents"; +import { DocUtils, Docs } from "../../documents/Documents"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { LinkDocPreview } from "./LinkDocPreview"; import { LinkCreatedBox } from "./LinkCreatedBox"; import { SelectionManager } from "../../util/SelectionManager"; import { Document } from "../../../fields/documentSchemas"; +import { StrCast } from "../../../fields/Types"; const higflyout = require("@hig/flyout"); export const { anchorPoints } = higflyout; @@ -29,6 +30,7 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp private _linkButton = React.createRef<HTMLDivElement>(); @observable public static StartLink: DocumentView | undefined; + @observable public static AnnotationId: string | undefined; componentDidMount() { // window.addEventListener("linkStarted", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created @@ -37,12 +39,13 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp // DocumentLinksButton.StartLink = element; // })); // }); - window.addEventListener("fakeLinkStarted", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created - console.log("Helo fake link"); - SelectionManager.SelectedDocuments().forEach(action((element: DocumentView) => { - DocumentLinksButton.StartLink = element; - })); - }); + window.addEventListener("fakeLinkStarted", action((e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created + console.log("Helo fake started link"); + const id = e.detail; + const source = SelectionManager.SelectedDocuments()[0]; + DocumentLinksButton.AnnotationId = id; + DocumentLinksButton.StartLink = source; + })); } @action @@ -101,12 +104,16 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp if (doubleTap) { if (DocumentLinksButton.StartLink === this.props.View) { DocumentLinksButton.StartLink = undefined; + DocumentLinksButton.AnnotationId = undefined; + console.log("reset to undefined (completeLink)"); // action((e: React.PointerEvent<HTMLDivElement>) => { // Doc.UnBrushDoc(this.props.View.Document); // }); } else { DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View && - DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag"); + (DocumentLinksButton.AnnotationId ? + DocUtils.MakeHypothesisLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "hypothesis annotation", DocumentLinksButton.AnnotationId) : + DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag")); runInAction(() => { LinkCreatedBox.popupX = e.screenX; @@ -123,12 +130,15 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp finishLinkClick = (e: React.MouseEvent) => { if (DocumentLinksButton.StartLink === this.props.View) { DocumentLinksButton.StartLink = undefined; + console.log("reset to undefined (finisheLinkClick)"); // action((e: React.PointerEvent<HTMLDivElement>) => { // Doc.UnBrushDoc(this.props.View.Document); // }); } else { DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View && - DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag"); + (DocumentLinksButton.AnnotationId ? + DocUtils.MakeHypothesisLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "hypothesis annotation", DocumentLinksButton.AnnotationId) : + DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag")); runInAction(() => { LinkCreatedBox.popupX = e.screenX; |
