From 15adf17efa078464643f8bcfd0f8c0b8afea8424 Mon Sep 17 00:00:00 2001
From: Melissa Zhang <mzhang19096@gmail.com>
Date: Mon, 6 Jul 2020 14:27:34 -0700
Subject: moved some API calls over to Dash

---
 src/client/views/nodes/DocumentView.tsx | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

(limited to 'src/client/views/nodes/DocumentView.tsx')

diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index 2285cb7e1..a0c90e2b2 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -43,6 +43,7 @@ import React = require("react");
 import { DocumentLinksButton } from './DocumentLinksButton';
 import { MobileInterface } from '../../../mobile/MobileInterface';
 import { LinkCreatedBox } from './LinkCreatedBox';
+import { Hypothesis } from '../../apis/hypothesis/HypothesisApiUtils';
 
 library.add(fa.faEdit, fa.faTrash, fa.faShare, fa.faDownload, fa.faExpandArrowsAlt, fa.faCompressArrowsAlt, fa.faLayerGroup, fa.faExternalLinkAlt, fa.faAlignCenter, fa.faCaretSquareRight,
     fa.faSquare, fa.faConciergeBell, fa.faWindowRestore, fa.faFolder, fa.faMapPin, fa.faLink, fa.faFingerprint, fa.faCrosshairs, fa.faDesktop, fa.faUnlock, fa.faLock, fa.faLaptopCode, fa.faMale,
@@ -756,13 +757,19 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
         if (!cm) return;
 
         cm.addItem({
-            description: "make hypothesis link", event: () => {
+            description: "make hypothesis link", event: async () => {
                 const docUrl = Utils.prepend("/doc/" + this.props.Document[Id]);
                 const docTitle = StrCast(this.layoutDoc.title);
-                document.dispatchEvent(new CustomEvent<{ url: string, title: string }>("linkRequest", {
-                    detail: { url: docUrl, title: docTitle },
-                    bubbles: true
-                }));
+                const getResponse = await Hypothesis.getAnnotation("melissaz", "placeholder");
+                if (getResponse && getResponse.rows.length > 0) {
+                    const annotationId = getResponse.rows[0].id;
+                    document.dispatchEvent(new CustomEvent<{ url: string, title: string, id: string }>("linkRequest", {
+                        detail: { url: docUrl, title: docTitle, id: annotationId },
+                        bubbles: true
+                    }));
+                } else {
+                    console.log("no placeholder annotation found");
+                }
             }, icon: "eye"
         });
 
-- 
cgit v1.2.3-70-g09d2

