From 1713f5415294b996e6dbbe9ca45f0f4511c69824 Mon Sep 17 00:00:00 2001
From: Melissa Zhang <mzhang19096@gmail.com>
Date: Mon, 3 Aug 2020 14:52:59 -0700
Subject: linking bug fixes, WebDocument size fixes

---
 src/client/views/MainView.tsx | 43 ++-----------------------------------------
 1 file changed, 2 insertions(+), 41 deletions(-)

(limited to 'src/client/views/MainView.tsx')

diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 954b8b998..5c34233b4 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -104,47 +104,7 @@ export class MainView extends React.Component {
                 }
             });
         });
-        document.addEventListener("linkAnnotationToDash", async (e: any) => {  // listen for event from Hypothes.is plugin to link an annotation to Dash
-            const annotationId = e.detail.id;
-            const annotationUri = e.detail.uri;
-            const sourceDoc = await Hypothesis.getSourceWebDoc(annotationUri);
-            console.log("sourceDoc: ", sourceDoc.title);
-
-            if (!DocumentLinksButton.StartLink) { // starts link only if there are none already started (else, a listener in DocumentLinksButton will handle link completion)
-                runInAction(() => {
-                    DocumentLinksButton.AnnotationId = annotationId;
-                    DocumentLinksButton.AnnotationUri = annotationUri;
-                    DocumentLinksButton.StartLink = sourceDoc;
-                });
-            } else { // if a link's already started in Dash, send event to DocumentLinksButton tofinish the link to the annotation
-                document.dispatchEvent(new CustomEvent<{ id: string, uri: string, sourceDoc: Doc }>("completeLinkToAnnotation", {
-                    detail: {
-                        id: annotationId,
-                        uri: annotationUri,
-                        sourceDoc: sourceDoc
-                    },
-                    bubbles: true
-                }));
-            }
-        });
-
-        // reaction(() => SelectionManager.SelectedDocuments(), selected => {
-        //     console.log("selection changed");
-        //     const selectedWebDocs = selected.map(docView => docView.props.Document).filter(doc => doc.type === DocumentType.WEB);
-        //     const urls = selectedWebDocs.map(doc => Cast(doc.data, WebField)?.url.href).filter(url => url !== undefined);
-        //     console.log("urls", urls);
-
-        //     const frame = document.getElementById('hyp_sidebar') as HTMLIFrameElement;
-        //     console.log("contentwindow?", frame.contentDocument);
-        //     if (frame.contentWindow) {
-        //         frame.contentWindow.postMessage("hello sidebar", window.origin);
-        //     }
-
-        //     document.dispatchEvent(new CustomEvent('showAnnotations', {
-        //         detail: urls,
-        //         bubbles: true
-        //     }));
-        // });
+        document.addEventListener("linkAnnotationToDash", Hypothesis.linkListener);
     }
 
     componentWillUnMount() {
@@ -152,6 +112,7 @@ export class MainView extends React.Component {
         window.removeEventListener("pointerdown", this.globalPointerDown);
         window.removeEventListener("pointerup", this.globalPointerUp);
         window.removeEventListener("paste", KeyManager.Instance.paste as any);
+        document.removeEventListener("linkAnnotationToDash", Hypothesis.linkListener);
     }
 
     constructor(props: Readonly<{}>) {
-- 
cgit v1.2.3-70-g09d2

