aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/hypothesis/HypothesisApiUtils.ts13
-rw-r--r--src/client/views/nodes/DocumentView.tsx17
2 files changed, 25 insertions, 5 deletions
diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts
new file mode 100644
index 000000000..714c9cdaf
--- /dev/null
+++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts
@@ -0,0 +1,13 @@
+export namespace Hypothesis {
+ export const getAnnotation = async (username: String, searchParam: String) => {
+ const base = 'https://api.hypothes.is/api/search';
+ const request = base + `?user=acct:${username}@hypothes.is&text=${searchParam}`;
+ console.log("DASH Querying " + request);
+ const response = await fetch(request);
+ if (response.ok) {
+ return response.json();
+ } else {
+ throw new Error('DASH: Error in GET request');
+ }
+ };
+} \ No newline at end of file
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"
});