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/views/nodes/DocumentLinksButton.tsx | 33 +++++++++----------------- 1 file changed, 11 insertions(+), 22 deletions(-) (limited to 'src/client/views/nodes/DocumentLinksButton.tsx') 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