aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-07-06 16:01:42 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-07-06 16:01:42 -0700
commit2e1284512f6f302673874ef3c368bdc50735f2a6 (patch)
treec6c875587ccc822fa111c29bce23ffb833613cda
parent15adf17efa078464643f8bcfd0f8c0b8afea8424 (diff)
set up linking from Dash documents to annotation
-rw-r--r--src/client/apis/hypothesis/HypothesisApiUtils.ts4
-rw-r--r--src/client/views/nodes/DocumentLinksButton.tsx18
-rw-r--r--src/client/views/nodes/DocumentView.tsx9
3 files changed, 31 insertions, 0 deletions
diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts
index 714c9cdaf..dc7e1f988 100644
--- a/src/client/apis/hypothesis/HypothesisApiUtils.ts
+++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts
@@ -10,4 +10,8 @@ export namespace Hypothesis {
throw new Error('DASH: Error in GET request');
}
};
+
+ export const makeAnnotationUrl = (annotationId: string, baseUrl: string) => {
+ return `https://hyp.is/${annotationId}/${baseUrl}`;
+ };
} \ No newline at end of file
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index bfd860f65..37d47700f 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -11,6 +11,9 @@ import { DocUtils } from "../../documents/Documents";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { LinkDocPreview } from "./LinkDocPreview";
import { LinkCreatedBox } from "./LinkCreatedBox";
+import { SelectionManager } from "../../util/SelectionManager";
+import { Document } from "../../../fields/documentSchemas";
+
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;
@@ -27,6 +30,21 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
@observable public static StartLink: DocumentView | undefined;
+ componentDidMount() {
+ // window.addEventListener("linkStarted", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created
+ // const annotatedUrl = e.details;
+ // SelectionManager.SelectedDocuments().forEach(action((element: DocumentView) => {
+ // DocumentLinksButton.StartLink = element;
+ // }));
+ // });
+ window.addEventListener("fakeLinkStarted", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created
+ console.log("Helo fake link");
+ SelectionManager.SelectedDocuments().forEach(action((element: DocumentView) => {
+ DocumentLinksButton.StartLink = element;
+ }));
+ });
+ }
+
@action
onLinkButtonMoved = (e: PointerEvent) => {
if (this._linkButton.current !== null) {
diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index a0c90e2b2..f42b72dbd 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -773,6 +773,15 @@ export class DocumentView extends DocComponent<DocumentViewProps, Document>(Docu
}, icon: "eye"
});
+ cm.addItem({
+ description: "pretend we made an annotation", event: () => {
+ document.dispatchEvent(new CustomEvent("fakeLinkStarted", {
+ detail: "hello this is fake",
+ 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" }));