aboutsummaryrefslogtreecommitdiff
path: root/src/client/views
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views')
-rw-r--r--src/client/views/MainView.tsx43
-rw-r--r--src/client/views/collections/collectionFreeForm/MarqueeView.tsx2
-rw-r--r--src/client/views/linking/LinkMenuItem.tsx7
-rw-r--r--src/client/views/nodes/DocumentLinksButton.tsx38
4 files changed, 10 insertions, 80 deletions
diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx
index 954b8b998..5c34233b4 100644
--- a/src/client/views/MainView.tsx
+++ b/src/client/views/MainView.tsx
@@ -104,47 +104,7 @@ 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
- 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
- }));
- }
- });
-
- // reaction(() => SelectionManager.SelectedDocuments(), selected => {
- // console.log("selection changed");
- // const selectedWebDocs = selected.map(docView => docView.props.Document).filter(doc => doc.type === DocumentType.WEB);
- // const urls = selectedWebDocs.map(doc => Cast(doc.data, WebField)?.url.href).filter(url => url !== undefined);
- // console.log("urls", urls);
-
- // const frame = document.getElementById('hyp_sidebar') as HTMLIFrameElement;
- // console.log("contentwindow?", frame.contentDocument);
- // if (frame.contentWindow) {
- // frame.contentWindow.postMessage("hello sidebar", window.origin);
- // }
-
- // document.dispatchEvent(new CustomEvent('showAnnotations', {
- // detail: urls,
- // bubbles: true
- // }));
- // });
+ document.addEventListener("linkAnnotationToDash", Hypothesis.linkListener);
}
componentWillUnMount() {
@@ -152,6 +112,7 @@ export class MainView extends React.Component {
window.removeEventListener("pointerdown", this.globalPointerDown);
window.removeEventListener("pointerup", this.globalPointerUp);
window.removeEventListener("paste", KeyManager.Instance.paste as any);
+ document.removeEventListener("linkAnnotationToDash", Hypothesis.linkListener);
}
constructor(props: Readonly<{}>) {
diff --git a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
index 764758eee..c3d81bda4 100644
--- a/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
+++ b/src/client/views/collections/collectionFreeForm/MarqueeView.tsx
@@ -74,7 +74,7 @@ export class MarqueeView extends React.Component<SubCollectionViewProps & Marque
if (e.key === "?") {
ContextMenu.Instance.setDefaultItem("?", (str: string) => {
const textDoc = Docs.Create.WebDocument(`https://bing.com/search?q=${str}`, {
- _width: 200, x, y, _nativeHeight: 962, _nativeWidth: 800, isAnnotating: false,
+ _width: 200, x, y, _nativeHeight: 962, _nativeWidth: 850, isAnnotating: false,
title: "bing", UseCors: true
});
this.props.addDocTab(textDoc, "onRight");
diff --git a/src/client/views/linking/LinkMenuItem.tsx b/src/client/views/linking/LinkMenuItem.tsx
index 8503bcbeb..40a16961a 100644
--- a/src/client/views/linking/LinkMenuItem.tsx
+++ b/src/client/views/linking/LinkMenuItem.tsx
@@ -11,7 +11,7 @@ import { ContextMenu } from '../ContextMenu';
import './LinkMenuItem.scss';
import React = require("react");
import { DocumentManager } from '../../util/DocumentManager';
-import { setupMoveUpEvents, emptyFunction, Utils } from '../../../Utils';
+import { setupMoveUpEvents, emptyFunction, Utils, simulateMouseClick } from '../../../Utils';
import { DocumentView } from '../nodes/DocumentView';
import { DocumentLinksButton } from '../nodes/DocumentLinksButton';
import { LinkDocPreview } from '../nodes/LinkDocPreview';
@@ -20,6 +20,7 @@ import { Id } from '../../../fields/FieldSymbols';
import { Tooltip } from '@material-ui/core';
import { DocumentType } from '../../documents/DocumentTypes';
import { undoBatch } from '../../util/UndoManager';
+import { WebField } from '../../../fields/URLField';
library.add(faEye, faEdit, faTimes, faArrowRight, faChevronDown, faChevronUp, faPencilAlt, faEyeSlash);
@@ -156,7 +157,7 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
const linkDoc = this.props.linkDoc;
if (linkDoc.followLinkLocation === "openExternal" && this.props.destinationDoc.type === DocumentType.WEB) {
- window.open(Hypothesis.makeAnnotationUrl(StrCast(linkDoc.annotationId), StrCast(linkDoc.annotationUri)), '_blank');
+ window.open(`${StrCast(linkDoc.annotationUri)}#annotations:${StrCast(linkDoc.annotationId)}`, '_blank');
return;
}
@@ -244,7 +245,7 @@ export class LinkMenuItem extends React.Component<LinkMenuItemProps> {
<FontAwesomeIcon className="destination-icon" icon={destinationIcon} size="sm" /></div>
<p className="linkMenu-destination-title"
onPointerDown={this.followDefault}>
- {this.props.linkDoc.linksToAnnotation ? "Annotation in" : ""} {title}
+ {this.props.linkDoc.linksToAnnotation && Cast(this.props.destinationDoc.data, WebField)?.url.href === this.props.linkDoc.annotationUri ? "Annotation in" : ""} {title}
</p>
</div>
{this.props.linkDoc.description !== "" ? <p className="linkMenu-description">
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index be7c3e135..3736cd3b2 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -40,35 +40,6 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
@observable public static AnnotationId: string | undefined;
@observable public static AnnotationUri: string | undefined;
- componentDidMount() {
- document.addEventListener("completeLinkToAnnotation", this.onLinkFromAnnotation);
- }
-
- componentWillUnmount() {
- document.removeEventListener("completeLinkToAnnotation", this.onLinkFromAnnotation);
- }
-
- @action
- onLinkFromAnnotation = async (e: any) => {
- 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");
- }
- }
-
@action @undoBatch
onLinkButtonMoved = (e: PointerEvent) => {
if (this.props.InMenu && this.props.StartLink) {
@@ -181,15 +152,12 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
setTimeout(action(() => DocumentLinksButton.StartLink!._link = this.props.View._link = undefined), 0);
LinkManager.currentLink = linkDoc;
- // if the link is to a Hypothes.is annotation
- if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) {
- // 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;
+ if (DocumentLinksButton.AnnotationId && DocumentLinksButton.AnnotationUri) { // if linking from a Hypothes.is annotation
+ const targetDoc = this.props.View.props.Document;
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(toBeLinked.title), Utils.prepend("/doc/" + toBeLinked[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation
+ Hypothesis.makeLink(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // edit annotation to add a Dash hyperlink to the linked doc
}
runInAction(() => {