diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-23 13:20:12 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-07-23 13:20:12 -0700 |
commit | 86a8751ca5a66fd42d7b2b3dee56210f2ef2b62d (patch) | |
tree | 694620d8360d60d883ac651869fb3b09ffe05a90 | |
parent | 90d5abaf3c32b53f34f6bd89e854c57c250937b0 (diff) |
adjustments to link following/editing behavior
-rw-r--r-- | src/client/apis/hypothesis/HypothesisApiUtils.ts | 22 | ||||
-rw-r--r-- | src/client/views/linking/LinkMenuItem.tsx | 4 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentLinksButton.tsx | 30 |
3 files changed, 43 insertions, 13 deletions
diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts index 2bffdb530..4c9fef45c 100644 --- a/src/client/apis/hypothesis/HypothesisApiUtils.ts +++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts @@ -1,5 +1,9 @@ -import { StrCast } from "../../../fields/Types"; +import { StrCast, Cast } from "../../../fields/Types"; import HypothesisAuthenticationManager from "../HypothesisAuthenticationManager"; +import { SearchUtil } from "../../util/SearchUtil"; +import { action } from "mobx"; +import { Doc } from "../../../fields/Doc"; +import { DocumentType } from "../../documents/DocumentTypes"; export namespace Hypothesis { @@ -94,4 +98,20 @@ export namespace Hypothesis { const regex = new RegExp('(?<=\:)(.*?)(?=\@)/'); return regex.exec(userid)![0]; }; + + // Return corres + export const getWebDocs = async (uri: string) => { + const results: Doc[] = []; + await SearchUtil.Search(uri, true).then(action(async (res: SearchUtil.DocSearchResult) => { + const docs = await Promise.all(res.docs.map(async doc => (await Cast(doc.extendsDoc, Doc)) || doc)); + const filteredDocs = docs.filter(doc => doc.type === DocumentType.WEB && doc.data); + + console.log("docs", docs); + console.log("FILTEREDDOCS: ", filteredDocs); + filteredDocs.forEach(doc => { + results.push(doc); + }); + })); + return results; + }; }
\ No newline at end of file diff --git a/src/client/views/linking/LinkMenuItem.tsx b/src/client/views/linking/LinkMenuItem.tsx index 509de2745..30571a165 100644 --- a/src/client/views/linking/LinkMenuItem.tsx +++ b/src/client/views/linking/LinkMenuItem.tsx @@ -154,7 +154,7 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> { DocumentLinksButton.EditLink = undefined; LinkDocPreview.LinkInfo = undefined; - this.props.linkDoc.linksToAnnotation && (Doc.GetProto(this.props.destinationDoc).data = new WebField(StrCast(this.props.linkDoc.annotationUrl))); // if destination is a Hypothes.is annotation, redirect website to the annotation's URL to scroll to the annotation + // this.props.linkDoc.linksToAnnotation && (Doc.GetProto(this.props.destinationDoc).data = new WebField(StrCast(this.props.linkDoc.annotationUrl))); // if destination is a Hypothes.is annotation, redirect website to the annotation's URL to scroll to the annotation if (this.props.linkDoc.follow) { if (this.props.linkDoc.follow === "Default") { @@ -167,6 +167,8 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> { } else { DocumentManager.Instance.FollowLink(this.props.linkDoc, this.props.sourceDoc, doc => this.props.addDocTab(doc, "onRight"), false); } + + this.props.linkDoc.linksToAnnotation && setTimeout(() => window.open(StrCast(this.props.linkDoc.annotationUrl), '_blank'), 1000); // open external page if hypothes.is annotation } @action diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx index d753edbeb..4c60d03fd 100644 --- a/src/client/views/nodes/DocumentLinksButton.tsx +++ b/src/client/views/nodes/DocumentLinksButton.tsx @@ -60,10 +60,18 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp } @action - linkAnnotation = async (e: any) => { // event used by hypothes.is plugin to tell Dash which annotation to link from + linkAnnotation = async (e: any) => { // event sent by hypothes.is plugin to tell Dash which annotation we're linking from const annotationId = e.detail.id; - const sourceUrl = e.detail.uri; - console.log(annotationId, sourceUrl); + 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; + }); } @action @@ -133,14 +141,14 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp const targetDoc = this.props.View.props.Document; const linkDoc = DocUtils.MakeLink({ doc: sourceDoc }, { doc: targetDoc }, DocumentLinksButton.AnnotationId ? "hypothes.is annotation" : "long drag"); - // not currently possible to drag hypothes.is annotation to form link - // if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) { - // const sourceUrl = DocumentLinksButton.AnnotationUri; - // Doc.GetProto(linkDoc as Doc).linksToAnnotation = true; - // Doc.GetProto(linkDoc as Doc).annotationId = DocumentLinksButton.AnnotationId; - // Doc.GetProto(linkDoc as Doc).annotationUrl = Hypothesis.makeAnnotationUrl(DocumentLinksButton.AnnotationId, sourceUrl); // redirect web doc to this URL when following link - // Hypothesis.makeLink(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation - // } + // TODO: Not currently possible to drag to complete links to annotations + if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) { + const sourceUrl = DocumentLinksButton.AnnotationUri; + Doc.GetProto(linkDoc as Doc).linksToAnnotation = true; + Doc.GetProto(linkDoc as Doc).annotationId = DocumentLinksButton.AnnotationId; + Doc.GetProto(linkDoc as Doc).annotationUrl = Hypothesis.makeAnnotationUrl(DocumentLinksButton.AnnotationId, sourceUrl); // redirect web doc to this URL when following link + Hypothesis.makeLink(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation + } LinkManager.currentLink = linkDoc; runInAction(() => { |