aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/LinkManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/LinkManager.ts')
-rw-r--r--src/client/util/LinkManager.ts54
1 files changed, 34 insertions, 20 deletions
diff --git a/src/client/util/LinkManager.ts b/src/client/util/LinkManager.ts
index 84ff3a3ff..90a8f2737 100644
--- a/src/client/util/LinkManager.ts
+++ b/src/client/util/LinkManager.ts
@@ -1,14 +1,12 @@
-import { observable, observe, action, reaction, computed } from "mobx";
+import { action, observable, observe } from "mobx";
import { computedFn } from "mobx-utils";
import { DirectLinksSym, Doc, DocListCast, Field, Opt } from "../../fields/Doc";
import { List } from "../../fields/List";
import { ProxyField } from "../../fields/Proxy";
-import { listSpec } from "../../fields/Schema";
-import { BoolCast, Cast, PromiseValue, StrCast } from "../../fields/Types";
+import { BoolCast, Cast, StrCast } from "../../fields/Types";
import { LightboxView } from "../views/LightboxView";
import { DocumentViewSharedProps, ViewAdjustment } from "../views/nodes/DocumentView";
import { DocumentManager } from "./DocumentManager";
-import { SharingManager } from "./SharingManager";
import { UndoManager } from "./UndoManager";
type CreateViewFunc = (doc: Doc, followLinkLocation: string, finished?: () => void) => void;
@@ -40,15 +38,19 @@ export class LinkManager {
const addLinkToDoc = (link: Doc) => {
const a1Prom = link?.anchor1;
const a2Prom = link?.anchor2;
- Promise.all([a1Prom, a2Prom]).then(action((all) => {
+ Promise.all([a1Prom, a2Prom]).then((all) => {
const a1 = all[0];
const a2 = all[1];
- if (a1 instanceof Doc && a2 instanceof Doc && ((a1.author !== undefined && a2.author !== undefined) || link.author === Doc.CurrentUserEmail)) {
- Doc.GetProto(a1)[DirectLinksSym].add(link);
- Doc.GetProto(a2)[DirectLinksSym].add(link);
- Doc.GetProto(link)[DirectLinksSym].add(link);
- }
- }));
+ const a1ProtoProm = (link?.anchor1 as Doc)?.proto;
+ const a2ProtoProm = (link?.anchor2 as Doc)?.proto;
+ Promise.all([a1ProtoProm, a2ProtoProm]).then(action((all) => {
+ if (a1 instanceof Doc && a2 instanceof Doc && ((a1.author !== undefined && a2.author !== undefined) || link.author === Doc.CurrentUserEmail)) {
+ Doc.GetProto(a1)[DirectLinksSym].add(link);
+ Doc.GetProto(a2)[DirectLinksSym].add(link);
+ Doc.GetProto(link)[DirectLinksSym].add(link);
+ }
+ }));
+ });
};
const remLinkFromDoc = (link: Doc) => {
const a1 = link?.anchor1;
@@ -102,12 +104,9 @@ export class LinkManager {
public createLinkrelationshipLists = () => {
//create new lists for link relations and their associated colors if the lists don't already exist
- if (!Doc.UserDoc().linkRelationshipList && !Doc.UserDoc().linkColorList) {
- const linkRelationshipList = new List<string>();
- const linkColorList = new List<string>();
- Doc.UserDoc().linkRelationshipList = linkRelationshipList;
- Doc.UserDoc().linkColorList = linkColorList;
- }
+ !Doc.UserDoc().linkRelationshipList && (Doc.UserDoc().linkRelationshipList = new List<string>());
+ !Doc.UserDoc().linkColorList && (Doc.UserDoc().linkColorList = new List<string>());
+ !Doc.UserDoc().linkRelationshipSizes && (Doc.UserDoc().linkRelationshipSizes = new List<number>());
}
public addLink(linkDoc: Doc, checkExists = false) {
@@ -120,14 +119,29 @@ export class LinkManager {
public getAllRelatedLinks(anchor: Doc) { return this.relatedLinker(anchor); } // finds all links that contain the given anchor
public getAllDirectLinks(anchor: Doc): Doc[] {
- return Array.from(Doc.GetProto(anchor)[DirectLinksSym]);
+ // FIXME:glr Why is Doc undefined?
+ if (Doc.GetProto(anchor)[DirectLinksSym]) {
+ return Array.from(Doc.GetProto(anchor)[DirectLinksSym]);
+ } else {
+ return [];
+ }
} // finds all links that contain the given anchor
relatedLinker = computedFn(function relatedLinker(this: any, anchor: Doc): Doc[] {
const lfield = Doc.LayoutFieldKey(anchor);
- const related = DocListCast(anchor[lfield + "-annotations"]).concat(DocListCast(anchor[lfield + "-annotations-timeline"])).reduce((list, anno) =>
+ if (!anchor || anchor instanceof Promise || Doc.GetProto(anchor) instanceof Promise) {
+ console.log("WAITING FOR DOC/PROTO IN LINKMANAGER");
+ return [];
+ }
+ const dirLinks = Doc.GetProto(anchor)[DirectLinksSym];
+ const annos = DocListCast(anchor[lfield + "-annotations"]);
+ const timelineAnnos = DocListCast(anchor[lfield + "-annotations-timeline"]);
+ if (!annos || !timelineAnnos) {
+ debugger;
+ }
+ const related = [...annos, ...timelineAnnos].reduce((list, anno) =>
[...list, ...LinkManager.Instance.relatedLinker(anno)],
- Array.from(Doc.GetProto(anchor)[DirectLinksSym]).slice());
+ Array.from(dirLinks).slice());
return related;
}, true);