From 4f16c24aa5221db8670fa69b7f7bee0f897fb203 Mon Sep 17 00:00:00 2001 From: Melissa Zhang Date: Fri, 10 Jul 2020 13:31:13 -0700 Subject: automatically starts link when an annotation is created --- src/client/apis/hypothesis/HypothesisApiUtils.ts | 3 ++- src/client/views/MainView.tsx | 4 --- src/client/views/nodes/DocumentLinksButton.tsx | 33 ++++++++---------------- src/client/views/nodes/DocumentView.tsx | 9 ------- 4 files changed, 13 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts index 9cd4b9f80..9ba481c8c 100644 --- a/src/client/apis/hypothesis/HypothesisApiUtils.ts +++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts @@ -65,7 +65,8 @@ export namespace Hypothesis { // Construct an URL which will scroll the web page to a specific annotation's position export const makeAnnotationUrl = (annotationId: string, baseUrl: string) => { - return `https://hyp.is/${annotationId}/${baseUrl}`; + return `https://hyp.is/${annotationId}/${baseUrl}`; // embeds the generic version of Hypothes.is client, not the Dash version + // return baseUrl + '#annotations:' + annotationId; }; // Extract username from Hypothe.is's userId format diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index cf1129895..81195b550 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -111,10 +111,6 @@ 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"); - // }); } componentWillUnMount() { diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx index 223d9fbf8..535711193 100644 --- a/src/client/views/nodes/DocumentLinksButton.tsx +++ b/src/client/views/nodes/DocumentLinksButton.tsx @@ -38,27 +38,17 @@ export class DocumentLinksButton extends React.Component { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created - // const id = e.details; - // const source = SelectionManager.SelectedDocuments()[0]; - // runInAction(() => { - // DocumentLinksButton.AnnotationId = id; - // DocumentLinksButton.StartLink = source; - // }); - // }); - console.log("window", window); - window.addEventListener("fakeAnnotationCreated", async (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created - if (e.handled) return; - e.handled = true; - console.log("Helo fake annotation make"); - // const id = e.detail; - const response = await Hypothesis.getPlaceholderId("bobzel", "placeholder"); // delete once eventListening between client & Dash works - const source = SelectionManager.SelectedDocuments()[0]; - response && runInAction(() => { - DocumentLinksButton.AnnotationId = response.id; - DocumentLinksButton.AnnotationUri = response.uri; - DocumentLinksButton.StartLink = source; - }); + window.addEventListener("message", async (e: any) => { + if (e.origin === "http://localhost:1050" && e.data.message === "annotation created") { + console.log("DASH RECEIVED MESSAGE:", e.data.message); + const response = await Hypothesis.getPlaceholderId("melissaz", "placeholder"); // delete once eventListening between client & Dash works + const source = SelectionManager.SelectedDocuments()[0]; + response && runInAction(() => { + DocumentLinksButton.AnnotationId = response.id; + DocumentLinksButton.AnnotationUri = response.uri; + DocumentLinksButton.StartLink = source; + }); + } }); } @@ -174,7 +164,6 @@ export class DocumentLinksButton extends React.Component(Docu const cm = ContextMenu.Instance; if (!cm) return; - cm.addItem({ - description: "pretend we made an annotation", event: () => { - document.dispatchEvent(new CustomEvent("fakeAnnotationCreated", { - detail: "fakefakefakeid", - bubbles: true - })); - }, icon: "eye" - }); - const customScripts = Cast(this.props.Document.contextMenuScripts, listSpec(ScriptField), []); Cast(this.props.Document.contextMenuLabels, listSpec("string"), []).forEach((label, i) => cm.addItem({ description: label, event: () => customScripts[i]?.script.run({ this: this.layoutDoc, self: this.rootDoc }), icon: "sticky-note" })); -- cgit v1.2.3-70-g09d2