aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-07-25 15:38:58 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-07-25 15:38:58 -0700
commitb1308d059c78e516c6062e4dd6f92dd409cf17a7 (patch)
tree69c83c46adfa55434606daa05636d9fe3ee2e642 /src
parent5ca85299fc42e5881b313053cf6c6fd2df572e12 (diff)
search for source web doc when linkToDash is called
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/hypothesis/HypothesisApiUtils.ts22
-rw-r--r--src/client/views/MainView.tsx4
2 files changed, 14 insertions, 12 deletions
diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts
index 4c9fef45c..cf265479a 100644
--- a/src/client/apis/hypothesis/HypothesisApiUtils.ts
+++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts
@@ -4,6 +4,7 @@ import { SearchUtil } from "../../util/SearchUtil";
import { action } from "mobx";
import { Doc } from "../../../fields/Doc";
import { DocumentType } from "../../documents/DocumentTypes";
+import { WebField } from "../../../fields/URLField";
export namespace Hypothesis {
@@ -75,8 +76,7 @@ export namespace Hypothesis {
const annotation = await fetchAnnotation(annotationId);
const regex = new RegExp(`(\[[^[]*)\(${linkUrl.replace('/', '\/')}\)`);
const target = regex.exec(annotation.text); // use regex to extract the link to be deleted, which is written in [title](hyperlink) format
- target && console.log(target);
- // target && editAnnotation(annotationId, annotation.text.replace(target[0], ''));
+ target && editAnnotation(annotationId, annotation.text.replace(target[0], ''));
};
// Finds the most recent placeholder annotation created and returns its ID
@@ -100,18 +100,20 @@ export namespace Hypothesis {
};
// Return corres
- export const getWebDocs = async (uri: string) => {
+ export const getSourceWebDoc = async (uri: string) => {
const results: Doc[] = [];
- await SearchUtil.Search(uri, true).then(action(async (res: SearchUtil.DocSearchResult) => {
+ await SearchUtil.Search("web", 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);
+ const filteredDocs = docs.filter(doc =>
+ doc.type === DocumentType.WEB && doc.data
+ );
filteredDocs.forEach(doc => {
- results.push(doc);
+ console.log(Cast(doc.data, WebField)?.url.href);
+ if (uri === Cast(doc.data, WebField)?.url.href) results.push(doc); // TODO check history? imperfect matches?
});
}));
- return results;
+
+ // TODO: open & return new Web doc with given uri if no matching Web docs are found
+ return results.length ? results[0] : undefined;
};
} \ No newline at end of file
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 6d18b3177..605b81506 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -132,8 +132,8 @@ export class MainView extends React.Component {
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 sourceDoc = await Hypothesis.getSourceWebDoc(annotationUri);
+ console.log("sourceDoc: ", sourceDoc ? sourceDoc.title : "not found");
const source = SelectionManager.SelectedDocuments()[0]; // TO BE FIXED, currently link just starts from whichever doc is selected
runInAction(() => {