diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-24 17:49:47 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-24 17:49:47 -0700 |
commit | 5ca85299fc42e5881b313053cf6c6fd2df572e12 (patch) | |
tree | 683c0e93efc7ff56bb4fb036b8f605a5593c90f7 /src/client/views/MainView.tsx | |
parent | 38b264599af2dca710b6c54d76cf30aade5e2f49 (diff) |
fix listeners for annotation listening
Diffstat (limited to 'src/client/views/MainView.tsx')
-rw-r--r-- | src/client/views/MainView.tsx | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index 225fb2e8e..6d18b3177 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -66,6 +66,8 @@ import { LinkDescriptionPopup } from './nodes/LinkDescriptionPopup'; import FormatShapePane from "./collections/collectionFreeForm/FormatShapePane"; import HypothesisAuthenticationManager from '../apis/HypothesisAuthenticationManager'; import CollectionMenu from './collections/CollectionMenu'; +import { Hypothesis } from '../apis/hypothesis/HypothesisApiUtils'; +import { SelectionManager } from '../util/SelectionManager'; @observer export class MainView extends React.Component { @@ -113,6 +115,33 @@ export class MainView extends React.Component { } }); }); + window.addEventListener("message", async (e: any) => { // listen for a new Hypothes.is annotation from an iframe inside Dash + // start link from new Hypothes.is annotation + // TODO: pass in placeholderId directly from client, move + if (e.origin === "http://localhost:1050" && e.data.message === "annotation created") { + console.log("DASH received message: annotation created"); + const response = await Hypothesis.getPlaceholderId("placeholder"); + const source = SelectionManager.SelectedDocuments()[0]; + response && runInAction(() => { + DocumentLinksButton.AnnotationId = response.id; + DocumentLinksButton.AnnotationUri = response.uri; + DocumentLinksButton.StartLink = source; + }); + } + }); + document.addEventListener("linkAnnotationToDash", async (e: any) => { // listen for event from Hypothes.is plugin to to link an existing annotation to Dash + const annotationId = e.detail.id; + const annotationUri = e.detail.uri; + console.log(annotationId, annotationUri); + // const source = await Hypothesis.getWebDoc(annotationUri); + + const source = SelectionManager.SelectedDocuments()[0]; // TO BE FIXED, currently link just starts from whichever doc is selected + runInAction(() => { + DocumentLinksButton.AnnotationId = annotationId; + DocumentLinksButton.AnnotationUri = annotationUri; + DocumentLinksButton.StartLink = source; + }); + }); } componentWillUnMount() { |