aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/DocumentLinksButton.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/DocumentLinksButton.tsx')
-rw-r--r--src/client/views/nodes/DocumentLinksButton.tsx73
1 files changed, 63 insertions, 10 deletions
diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index 7fb447cab..32c344304 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -1,18 +1,24 @@
import { action, computed, observable, runInAction } from "mobx";
import { observer } from "mobx-react";
import { Doc, DocListCast } from "../../../fields/Doc";
-import { emptyFunction, setupMoveUpEvents, returnFalse } from "../../../Utils";
+import { emptyFunction, setupMoveUpEvents, returnFalse, Utils } from "../../../Utils";
import { DragManager } from "../../util/DragManager";
import { UndoManager } from "../../util/UndoManager";
import './DocumentLinksButton.scss';
import { DocumentView } from "./DocumentView";
import React = require("react");
-import { DocUtils } from "../../documents/Documents";
+import { DocUtils, Docs } from "../../documents/Documents";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { LinkDocPreview } from "./LinkDocPreview";
import { LinkCreatedBox } from "./LinkCreatedBox";
+import { SelectionManager } from "../../util/SelectionManager";
+import { Document } from "../../../fields/documentSchemas";
+import { StrCast } from "../../../fields/Types";
+
import { LinkDescriptionPopup } from "./LinkDescriptionPopup";
import { LinkManager } from "../../util/LinkManager";
+import { Hypothesis } from "../../apis/hypothesis/HypothesisApiUtils";
+import { Id } from "../../../fields/FieldSymbols";
const higflyout = require("@hig/flyout");
export const { anchorPoints } = higflyout;
export const Flyout = higflyout.default;
@@ -28,6 +34,29 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
private _linkButton = React.createRef<HTMLDivElement>();
@observable public static StartLink: DocumentView | undefined;
+ @observable public static AnnotationId: string | undefined;
+
+ componentDidMount() {
+ // window.addEventListener("annotationCreated", (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created
+ // const id = e.details;
+ // const source = SelectionManager.SelectedDocuments()[0];
+ // runInAction(() => {
+ // DocumentLinksButton.AnnotationId = id;
+ // DocumentLinksButton.StartLink = source;
+ // });
+ // });
+ console.log("window", window);
+ window.addEventListener("fakeAnnotationCreated", async (e: any) => { // event used by Hypothes.is plugin to tell Dash when an unlinked annotation has been created
+ console.log("Helo fake annotation make");
+ // const id = e.detail;
+ const id = await Hypothesis.getPlaceholderId("melissaz", "placeholder"); // delete once eventListening between client & Dash works
+ const source = SelectionManager.SelectedDocuments()[0];
+ runInAction(() => {
+ DocumentLinksButton.AnnotationId = id;
+ DocumentLinksButton.StartLink = source;
+ });
+ });
+ }
@action
onLinkButtonMoved = (e: PointerEvent) => {
@@ -86,13 +115,25 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
if (doubleTap) {
if (DocumentLinksButton.StartLink === this.props.View) {
DocumentLinksButton.StartLink = undefined;
+ DocumentLinksButton.AnnotationId = undefined;
+ console.log("reset to undefined (completeLink)");
// action((e: React.PointerEvent<HTMLDivElement>) => {
// Doc.UnBrushDoc(this.props.View.Document);
// });
} else {
-
if (DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View) {
- const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag");
+ const sourceDoc = DocumentLinksButton.StartLink.props.Document;
+ const targetDoc = this.props.View.props.Document;
+ const linkDoc = DocUtils.MakeLink({ doc: sourceDoc }, { doc: targetDoc }, DocumentLinksButton.AnnotationId ? "hypothes.is annotation" : "long drag");
+
+ // if the link's source is a Hypothes.is annotation
+ if (DocumentLinksButton.AnnotationId) {
+ const sourceUrl = StrCast(sourceDoc.data.url); // the URL of the annotation's source web page
+ Doc.GetProto(linkDoc as Doc).linksToAnnotation = true;
+ Doc.GetProto(linkDoc as Doc).annotationUrl = Hypothesis.makeAnnotationUrl(DocumentLinksButton.AnnotationId, sourceUrl); // redirect web doc to this URL when following link
+ Hypothesis.dispatchLinkRequest(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation
+ }
+
LinkManager.currentLink = linkDoc;
runInAction(() => {
LinkCreatedBox.popupX = e.screenX;
@@ -115,23 +156,35 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
finishLinkClick = (e: React.MouseEvent) => {
if (DocumentLinksButton.StartLink === this.props.View) {
DocumentLinksButton.StartLink = undefined;
+ DocumentLinksButton.AnnotationId = undefined;
+ console.log("reset to undefined (finisheLinkClick)");
// action((e: React.PointerEvent<HTMLDivElement>) => {
// Doc.UnBrushDoc(this.props.View.Document);
// });
} else {
if (DocumentLinksButton.StartLink && DocumentLinksButton.StartLink !== this.props.View) {
- const linkDoc = DocUtils.MakeLink({ doc: DocumentLinksButton.StartLink.props.Document }, { doc: this.props.View.props.Document }, "long drag");
+ const sourceDoc = DocumentLinksButton.StartLink.props.Document;
+ const targetDoc = this.props.View.props.Document;
+ const linkDoc = DocUtils.MakeLink({ doc: sourceDoc }, { doc: targetDoc }, DocumentLinksButton.AnnotationId ? "hypothes.is annotation" : "long drag");
+
+ // if the link is to a Hypothes.is annotation
+ if (DocumentLinksButton.AnnotationId) {
+ const sourceUrl = StrCast(sourceDoc.data.url); // the URL of the annotation's source web page
+ console.log("sourceAnnotationId, url", DocumentLinksButton.AnnotationId, sourceUrl);
+ Doc.GetProto(linkDoc as Doc).linksToAnnotation = true;
+ Doc.GetProto(linkDoc as Doc).annotationUrl = Hypothesis.makeAnnotationUrl(DocumentLinksButton.AnnotationId, sourceUrl); // redirect web doc to this URL when following link
+ Hypothesis.dispatchLinkRequest(StrCast(targetDoc.title), Utils.prepend("/doc/" + targetDoc[Id]), DocumentLinksButton.AnnotationId); // update and link placeholder annotation
+ }
+
LinkManager.currentLink = linkDoc;
runInAction(() => {
LinkCreatedBox.popupX = e.screenX;
LinkCreatedBox.popupY = e.screenY - 133;
LinkCreatedBox.linkCreated = true;
- if (LinkDescriptionPopup.showDescriptions === "ON" || !LinkDescriptionPopup.showDescriptions) {
- LinkDescriptionPopup.popupX = e.screenX;
- LinkDescriptionPopup.popupY = e.screenY - 100;
- LinkDescriptionPopup.descriptionPopup = true;
- }
+ LinkDescriptionPopup.popupX = e.screenX;
+ LinkDescriptionPopup.popupY = e.screenY - 100;
+ LinkDescriptionPopup.descriptionPopup = true;
setTimeout(action(() => { LinkCreatedBox.linkCreated = false; }), 2500);
});