aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-08-04 19:31:24 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-08-04 19:31:24 -0700
commit6fe4cfc95f061928a7040878ae90cd1df5f181e9 (patch)
tree1c37cf65428f00bb7fffebe290dcaac6cecf821b /src
parentbd6b5a81480f7f56a65c13954e080281279b6627 (diff)
clean hypothes.is urls, change web doc default to non-annotation mode
Diffstat (limited to 'src')
-rw-r--r--src/client/apis/hypothesis/HypothesisUtils.ts11
-rw-r--r--src/client/documents/Documents.ts2
-rw-r--r--src/client/views/collections/CollectionSubView.tsx2
3 files changed, 7 insertions, 8 deletions
diff --git a/src/client/apis/hypothesis/HypothesisUtils.ts b/src/client/apis/hypothesis/HypothesisUtils.ts
index f3ff196a8..16f132e97 100644
--- a/src/client/apis/hypothesis/HypothesisUtils.ts
+++ b/src/client/apis/hypothesis/HypothesisUtils.ts
@@ -17,15 +17,16 @@ import { DocumentView } from "../../views/nodes/DocumentView";
export namespace Hypothesis {
+ // Retrieve a WebDocument with the given url exists, create and return a new
export const getSourceWebDoc = async (uri: string) => {
const result = await findWebDoc(uri);
- return result || Docs.Create.WebDocument(uri, { _nativeWidth: 850, _nativeHeight: 962, _width: 600, UseCors: true }); // create and return a new Web doc with given uri if no matching docs are found
+ console.log(result ? "existing doc found" : "existing doc NOT found");
+ return result || Docs.Create.WebDocument(uri, { title: uri, _nativeWidth: 850, _nativeHeight: 962, _width: 400, UseCors: true }); // create and return a new Web doc with given uri if no matching docs are found
};
- // Search for a web Doc whose url field matches the given uri, return undefined if not found
+ // Search for a WebDocument whose url field matches the given uri, return undefined if not found
export const findWebDoc = async (uri: string) => {
const currentDoc = SelectionManager.SelectedDocuments().length && SelectionManager.SelectedDocuments()[0].props.Document;
- currentDoc && console.log(Cast(currentDoc.data, WebField)?.url.href === uri, uri, Cast(currentDoc.data, WebField)?.url.href);
if (currentDoc && Cast(currentDoc.data, WebField)?.url.href === uri) return currentDoc; // always check first whether the current doc is the source, only resort to Search otherwise
const results: Doc[] = [];
@@ -38,8 +39,6 @@ export namespace Hypothesis {
filteredDocs.forEach(doc => { uri === Cast(doc.data, WebField)?.url.href && results.push(doc); }); // TODO check history? imperfect matches?
}));
- results.forEach(doc => console.log(doc.title, StrCast(doc.data)));
-
return results.length ? results[0] : undefined;
};
@@ -111,7 +110,7 @@ export namespace Hypothesis {
// listen for event from Hypothes.is plugin to link an annotation to Dash
export const linkListener = async (e: any) => {
const annotationId: string = e.detail.id;
- const annotationUri: string = e.detail.uri;
+ const annotationUri: string = StrCast(e.detail.uri).split("#annotations:")[0]; // clean hypothes.is URLs that reference a specific annotation (eg. https://en.wikipedia.org/wiki/Cartoon#annotations:t7qAeNbCEeqfG5972KR2Ig)
const sourceDoc: Doc = await getSourceWebDoc(annotationUri);
if (!DocumentLinksButton.StartLink) { // start link if there were none already started
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 3ee7ed87a..725dacb5d 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -708,7 +708,7 @@ export namespace Docs {
}
export function WebDocument(url: string, options: DocumentOptions = {}) {
- return InstanceFromProto(Prototypes.get(DocumentType.WEB), url ? new WebField(new URL(url)) : undefined, { _fitWidth: true, _chromeStatus: url ? "disabled" : "enabled", isAnnotating: true, _lockedTransform: true, ...options });
+ return InstanceFromProto(Prototypes.get(DocumentType.WEB), url ? new WebField(new URL(url)) : undefined, { _fitWidth: true, _chromeStatus: url ? "disabled" : "enabled", isAnnotating: false, _lockedTransform: true, ...options });
}
export function HtmlDocument(html: string, options: DocumentOptions = {}) {
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index b66da27b4..2c382fe88 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -351,7 +351,7 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
if (existingWebDoc) {
this.addDocument(Doc.MakeAlias(existingWebDoc));
} else {
- const cleanedUri = uriList.split("#annotations:")[0]; // clean hypothes.is URLs that scroll directly to an annotation
+ const cleanedUri = uriList.split("#annotations:")[0]; // clean hypothes.is URLs that reference a specific annotation (eg. https://en.wikipedia.org/wiki/Cartoon#annotations:t7qAeNbCEeqfG5972KR2Ig)
this.addDocument(Docs.Create.WebDocument(uriList, {
...options,
title: cleanedUri,