diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-10 10:25:42 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-10 10:25:42 -0700 |
commit | a721dabf0432286f60bd33bef8a80159b04b6e53 (patch) | |
tree | 438f5a53c2897f9702d186c7a88666f9b01cc406 /src | |
parent | c10798535cbf1854c9b9ba51f119d24fcc613de4 (diff) | |
parent | 5e22d4aa9eefb8c92859fc0d1adb508429af2106 (diff) |
pull changes
Diffstat (limited to 'src')
-rw-r--r-- | src/client/apis/hypothesis/HypothesisApiUtils.ts | 5 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentLinksButton.tsx | 18 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts index f31fa60a1..9cd4b9f80 100644 --- a/src/client/apis/hypothesis/HypothesisApiUtils.ts +++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts @@ -43,12 +43,13 @@ export namespace Hypothesis { export const getPlaceholderId = async (username: string, searchKeyWord: string) => { const getResponse = await Hypothesis.searchAnnotation(username, searchKeyWord); const id = getResponse.rows.length > 0 ? getResponse.rows[0].id : undefined; - return StrCast(id); + const uri = getResponse.rows.length > 0 ? getResponse.rows[0].uri : undefined; + return id ? { id, uri } : undefined; }; // Send request to Hypothes.is client to modify a placeholder annotation into a hyperlink to Dash export const dispatchLinkRequest = async (title: string, url: string, annotationId: string) => { - const apiKey = "6879-GHmtDG_P2kmWNKM3hcHptEUZX3VMOUePkamCaOrJbSw"; + const apiKey = "6879-DnMTKjWjnnLPa0Php7f5Ra2kunZ_X0tMRDbTF220_q0"; const oldAnnotation = await fetchAnnotation(annotationId); const oldText = StrCast(oldAnnotation.text); diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx index 32c344304..223d9fbf8 100644 --- a/src/client/views/nodes/DocumentLinksButton.tsx +++ b/src/client/views/nodes/DocumentLinksButton.tsx @@ -35,6 +35,7 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp @observable public static StartLink: DocumentView | undefined; @observable public static AnnotationId: string | undefined; + @observable public static AnnotationUri: string | undefined; componentDidMount() { // window.addEventListener("annotationCreated", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created @@ -47,12 +48,15 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp // }); console.log("window", window); window.addEventListener("fakeAnnotationCreated", async (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created + if (e.handled) return; + e.handled = true; console.log("Helo fake annotation make"); // const id = e.detail; - const id = await Hypothesis.getPlaceholderId("melissaz", "placeholder"); // delete once eventListening between client & Dash works + const response = await Hypothesis.getPlaceholderId("bobzel", "placeholder"); // delete once eventListening between client & Dash works const source = SelectionManager.SelectedDocuments()[0]; - runInAction(() => { - DocumentLinksButton.AnnotationId = id; + response && runInAction(() => { + DocumentLinksButton.AnnotationId = response.id; + DocumentLinksButton.AnnotationUri = response.uri; DocumentLinksButton.StartLink = source; }); }); @@ -127,8 +131,8 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp const linkDoc = DocUtils.MakeLink({ doc: sourceDoc }, { doc: targetDoc }, DocumentLinksButton.AnnotationId ? "hypothes.is annotation" : "long drag"); // if the link's source is a Hypothes.is annotation - if (DocumentLinksButton.AnnotationId) { - const sourceUrl = StrCast(sourceDoc.data.url); // the URL of the annotation's source web page + if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) { + const sourceUrl = DocumentLinksButton.AnnotationUri; Doc.GetProto(linkDoc as Doc).linksToAnnotation = true; Doc.GetProto(linkDoc as Doc).annotationUrl = Hypothesis.makeAnnotationUrl(DocumentLinksButton.AnnotationId, sourceUrl); // redirect web doc to this URL when following link Hypothesis.dispatchLinkRequest(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation @@ -168,8 +172,8 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp const linkDoc = DocUtils.MakeLink({ doc: sourceDoc }, { doc: targetDoc }, DocumentLinksButton.AnnotationId ? "hypothes.is annotation" : "long drag"); // if the link is to a Hypothes.is annotation - if (DocumentLinksButton.AnnotationId) { - const sourceUrl = StrCast(sourceDoc.data.url); // the URL of the annotation's source web page + if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) { + const sourceUrl = DocumentLinksButton.AnnotationUri; // the URL of the annotation's source web page console.log("sourceAnnotationId, url", DocumentLinksButton.AnnotationId, sourceUrl); Doc.GetProto(linkDoc as Doc).linksToAnnotation = true; Doc.GetProto(linkDoc as Doc).annotationUrl = Hypothesis.makeAnnotationUrl(DocumentLinksButton.AnnotationId, sourceUrl); // redirect web doc to this URL when following link |