From fbc7a328016af60052dd3f33c2d906e6c6447a5f Mon Sep 17 00:00:00 2001 From: Melissa Zhang Date: Mon, 6 Jul 2020 23:41:34 -0700 Subject: set up linking for hypothesis annotations --- src/client/views/MainView.tsx | 8 +++---- .../views/collections/CollectionLinearView.tsx | 2 +- src/client/views/nodes/DocumentLinksButton.tsx | 28 +++++++++++++++------- src/client/views/nodes/DocumentView.tsx | 2 +- 4 files changed, 25 insertions(+), 15 deletions(-) (limited to 'src/client/views') diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index 65d585a2a..4c3add663 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -108,10 +108,10 @@ export class MainView extends React.Component { } }); }); - document.addEventListener("linkComplete", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an annotation has been linked - const annotatedUrl = e.details; - console.log("This website " + annotatedUrl + " has a linked annotation"); - }); + // document.addEventListener("linkComplete", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an annotation has been linked + // const annotatedUrl = e.details; + // console.log("This website " + annotatedUrl + " has a linked annotation"); + // }); } componentWillUnMount() { diff --git a/src/client/views/collections/CollectionLinearView.tsx b/src/client/views/collections/CollectionLinearView.tsx index 7cbe5c19d..fd8eb506a 100644 --- a/src/client/views/collections/CollectionLinearView.tsx +++ b/src/client/views/collections/CollectionLinearView.tsx @@ -154,7 +154,7 @@ export class CollectionLinearView extends CollectionSubView(LinearDocument) { }} onPointerDown={e => e.stopPropagation()} > - Creating link from: {DocumentLinksButton.StartLink.title} + Creating link from: {(DocumentLinksButton.AnnotationId ? "Annotation in " : "")} {DocumentLinksButton.StartLink.title} Exit 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(); @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 { // 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) => { // 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 { if (DocumentLinksButton.StartLink === this.props.View) { DocumentLinksButton.StartLink = undefined; + console.log("reset to undefined (finisheLinkClick)"); // action((e: React.PointerEvent) => { // 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; diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index f42b72dbd..128a56c19 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -776,7 +776,7 @@ export class DocumentView extends DocComponent(Docu cm.addItem({ description: "pretend we made an annotation", event: () => { document.dispatchEvent(new CustomEvent("fakeLinkStarted", { - detail: "hello this is fake", + detail: "fakefakefakeid", bubbles: true })); }, icon: "eye" -- cgit v1.2.3-70-g09d2