aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMelissa Zhang <mzhang19096@gmail.com>2020-07-31 16:03:03 -0700
committerMelissa Zhang <mzhang19096@gmail.com>2020-07-31 16:03:03 -0700
commit2b3fb53a5e0ebe21eef2406992257ef5e86b3b2d (patch)
tree2be488ccee4d8eb17eb02e22a9acd00ab1933650 /src
parent3e6dfbb32b9cafaafe178c8e8e427207a17325e2 (diff)
modify link completing from annotations, fix web drag & drop
Diffstat (limited to 'src')
-rw-r--r--src/client/views/MainView.tsx19
-rw-r--r--src/client/views/collections/CollectionSubView.tsx5
-rw-r--r--src/client/views/nodes/DocumentLinksButton.tsx46
3 files changed, 43 insertions, 27 deletions
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 93e4d1a6f..954b8b998 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -105,17 +105,26 @@ export class MainView extends React.Component {
});
});
document.addEventListener("linkAnnotationToDash", async (e: any) => { // listen for event from Hypothes.is plugin to link an annotation to Dash
- if (!DocumentLinksButton.StartLink) { // starts link only if there are none already started (else, a listener in DocumentLinksButton will handle link completion)
- const annotationId = e.detail.id;
- const annotationUri = e.detail.uri;
- const sourceDoc = await Hypothesis.getSourceWebDoc(annotationUri);
- console.log("sourceDoc: ", sourceDoc.title);
+ const annotationId = e.detail.id;
+ const annotationUri = e.detail.uri;
+ const sourceDoc = await Hypothesis.getSourceWebDoc(annotationUri);
+ console.log("sourceDoc: ", sourceDoc.title);
+ if (!DocumentLinksButton.StartLink) { // starts link only if there are none already started (else, a listener in DocumentLinksButton will handle link completion)
runInAction(() => {
DocumentLinksButton.AnnotationId = annotationId;
DocumentLinksButton.AnnotationUri = annotationUri;
DocumentLinksButton.StartLink = sourceDoc;
});
+ } else { // if a link's already started in Dash, send event to DocumentLinksButton tofinish the link to the annotation
+ document.dispatchEvent(new CustomEvent<{ id: string, uri: string, sourceDoc: Doc }>("completeLinkToAnnotation", {
+ detail: {
+ id: annotationId,
+ uri: annotationUri,
+ sourceDoc: sourceDoc
+ },
+ bubbles: true
+ }));
}
});
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 9f78c15eb..2957f004b 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -353,8 +353,9 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
title: uriList,
_width: 400,
_height: 315,
- _nativeWidth: 600,
- _nativeHeight: 472.5
+ _nativeWidth: 850,
+ _nativeHeight: 962,
+ UseCors: true
}));
return;
}
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index 581d84eae..be7c3e135 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -11,13 +11,14 @@ import { DragManager } from "../../util/DragManager";
import { LinkManager } from "../../util/LinkManager";
import { undoBatch, UndoManager } from "../../util/UndoManager";
import { DocumentView } from "./DocumentView";
-import { StrCast } from "../../../fields/Types";
+import { StrCast, Cast } from "../../../fields/Types";
import { LinkDescriptionPopup } from "./LinkDescriptionPopup";
import { Hypothesis } from "../../apis/hypothesis/HypothesisUtils";
import { Id } from "../../../fields/FieldSymbols";
import { TaskCompletionBox } from "./TaskCompletedBox";
import React = require("react");
import './DocumentLinksButton.scss';
+import { WebField } from "../../../fields/URLField";
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
@@ -40,27 +41,30 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
@observable public static AnnotationUri: string | undefined;
componentDidMount() {
- document.addEventListener("linkAnnotationToDash", this.onLinkFromAnnotation);
+ document.addEventListener("completeLinkToAnnotation", this.onLinkFromAnnotation);
}
componentWillUnmount() {
- document.removeEventListener("linkAnnotationToDash", this.onLinkFromAnnotation);
+ document.removeEventListener("completeLinkToAnnotation", this.onLinkFromAnnotation);
}
+ @action
onLinkFromAnnotation = async (e: any) => {
- const annotationUri = e.detail.uri;
- const sourceDoc = DocumentLinksButton.StartLink && await Hypothesis.getSourceWebDoc(annotationUri);
-
- this.props.View.props.Document.type === DocumentType.WEB && console.log(sourceDoc === this.props.View.props.Document,
- sourceDoc,
- this.props.View.props.Document,
- sourceDoc!.title,
- this.props.View.props.Document,
- sourceDoc!.data,
- this.props.View.props.Document.data);
-
- if (sourceDoc === this.props.View.props.Document && sourceDoc !== DocumentLinksButton.StartLink) {
- this.finishLinkClick(20, 20);
+ const annotationId: string = e.detail.id;
+ const annotationUri: string = e.detail.uri;
+ const sourceDoc: Doc = e.detail.sourceDoc;
+
+ // DocumentLinksButton.StartLink && this.props.View.props.Document.type === DocumentType.WEB && console.log(
+ // sourceDoc.title,
+ // this.props.View.props.Document.title,
+ // sourceDoc.data,
+ // this.props.View.props.Document.data,
+ // Doc.AreProtosEqual(sourceDoc, this.props.View.props.Document));
+
+ if (Doc.AreProtosEqual(sourceDoc, this.props.View.props.Document) && sourceDoc !== DocumentLinksButton.StartLink) {
+ DocumentLinksButton.AnnotationId = annotationId;
+ DocumentLinksButton.AnnotationUri = annotationUri;
+ this.finishLinkClick(500, 100);
console.log("completed link from annotation");
}
}
@@ -122,7 +126,7 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
@action @undoBatch
completeLink = (e: React.PointerEvent): void => {
setupMoveUpEvents(this, e, returnFalse, emptyFunction, action((e, doubleTap) => {
- if (doubleTap && this.props.InMenu && !!!this.props.StartLink) {
+ if (doubleTap && !this.props.StartLink) {
if (DocumentLinksButton.StartLink === this.props.View.props.Document) {
DocumentLinksButton.StartLink = undefined;
DocumentLinksButton.AnnotationId = undefined;
@@ -169,7 +173,7 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
DocumentLinksButton.StartLink = undefined;
DocumentLinksButton.AnnotationId = undefined;
} else {
- if (this.props.InMenu && !!!this.props.StartLink) {
+ if (!this.props.StartLink) {
if (DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View.props.Document) {
const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink }, { doc: this.props.View.props.Document }, DocumentLinksButton.AnnotationId ? "hypothes.is annotation" : "long drag");
// this notifies any of the subviews that a document is made so that they can make finer-grained hyperlinks (). see note above in onLInkButtonMoved
@@ -179,11 +183,13 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
// if the link is to a Hypothes.is annotation
if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) {
- const targetDoc = this.props.View.props.Document;
+ // figure out whether the StartLink doc or the current doc is the one to be linked to the annotation (the one NOT containing the annotation)
+ const toBeLinked: Doc = DocumentLinksButton.AnnotationUri === Cast(DocumentLinksButton.StartLink.data, WebField)?.url.href ?
+ this.props.View.props.Document : DocumentLinksButton.StartLink;
Doc.GetProto(linkDoc as Doc).linksToAnnotation = true;
Doc.GetProto(linkDoc as Doc).annotationId = DocumentLinksButton.AnnotationId;
Doc.GetProto(linkDoc as Doc).annotationUri = DocumentLinksButton.AnnotationUri;
- Hypothesis.makeLink(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation
+ Hypothesis.makeLink(StrCast(toBeLinked.title), Utils.prepend("/doc/" + toBeLinked[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation
}
runInAction(() => {