diff options
author | Hannah Chow <hannah_chow@brown.edu> | 2019-03-07 01:56:46 -0500 |
---|---|---|
committer | Hannah Chow <hannah_chow@brown.edu> | 2019-03-07 01:56:46 -0500 |
commit | 69d42193bf187a8a61e475a0587d55e29b644394 (patch) | |
tree | 3b2808529448a5775cff1299e572137b920961e7 /src | |
parent | 6bd826932b3c749c89581debe3eed0380ede9e4e (diff) |
following the link
Diffstat (limited to 'src')
-rw-r--r-- | src/client/util/DocumentManager.ts | 51 | ||||
-rw-r--r-- | src/client/views/nodes/DocumentView.tsx | 10 | ||||
-rw-r--r-- | src/client/views/nodes/LinkBox.tsx | 5 |
3 files changed, 65 insertions, 1 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts new file mode 100644 index 000000000..5b99b4ef8 --- /dev/null +++ b/src/client/util/DocumentManager.ts @@ -0,0 +1,51 @@ +import React = require('react') +import { observer } from 'mobx-react'; +import { observable, action } from 'mobx'; +import { Document } from "../../fields/Document" +import { DocumentView } from '../views/nodes/DocumentView'; + + +export class DocumentManager { + + //global holds all of the nodes (regardless of which collection they're in) + @observable + public DocumentViews: DocumentView[] = []; + + // singleton instance + private static _instance: DocumentManager; + + // create one and only one instance of NodeManager + public static get Instance(): DocumentManager { + return this._instance || (this._instance = new this()); + } + + //private constructor so no other class can create a nodemanager + private constructor() { + // this.DocumentViews = new Array<DocumentView>(); + } + + public getDocumentView(toFind: Document): DocumentView | null { + + let toReturn: DocumentView | null; + toReturn = null; + + //gets document view that is in a freeform canvas collection + DocumentManager.Instance.DocumentViews.map(view => { + let doc = view.props.Document; + // if (view.props.ContainingCollectionView instanceof CollectionFreeFormView) { + // if (Object.is(doc, toFind)) { + // toReturn = view; + // return; + // } + // } + + if (Object.is(doc, toFind)) { + toReturn = view; + return; + } + + }) + + return (toReturn); + } +}
\ No newline at end of file diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index c9afbb150..d80abb460 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -1,4 +1,4 @@ -import { action, computed } from "mobx"; +import { action, computed, runInAction } from "mobx"; import { observer } from "mobx-react"; import { Document } from "../../../fields/Document"; import { Field, FieldWaiting, Opt } from "../../../fields/Field"; @@ -21,6 +21,7 @@ import { WebBox } from "../nodes/WebBox"; import "./DocumentView.scss"; import React = require("react"); import { TextField } from "../../../fields/TextField"; +import { DocumentManager } from "../../util/DocumentManager"; const JsxParser = require('react-jsx-parser').default; //TODO Why does this need to be imported like this? @@ -120,6 +121,9 @@ export class DocumentView extends React.Component<DocumentViewProps> { if (this._mainCont.current) { this.dropDisposer = DragManager.MakeDropTarget(this._mainCont.current, { handlers: { drop: this.drop.bind(this) } }); } + runInAction(() => { + DocumentManager.Instance.DocumentViews.push(this); + }) } componentDidUpdate() { @@ -135,6 +139,10 @@ export class DocumentView extends React.Component<DocumentViewProps> { if (this.dropDisposer) { this.dropDisposer(); } + runInAction(() => { + DocumentManager.Instance.DocumentViews.splice(DocumentManager.Instance.DocumentViews.indexOf(this), 1); + + }) } onPointerMove = (e: PointerEvent): void => { diff --git a/src/client/views/nodes/LinkBox.tsx b/src/client/views/nodes/LinkBox.tsx index ee281e2ee..25556d5be 100644 --- a/src/client/views/nodes/LinkBox.tsx +++ b/src/client/views/nodes/LinkBox.tsx @@ -8,6 +8,7 @@ import { props } from "bluebird"; import { DocumentView } from "./DocumentView"; import { Document } from "../../../fields/Document"; import { ListField } from "../../../fields/ListField"; +import { DocumentManager } from "../../util/DocumentManager"; interface Props { linkDoc: Document; @@ -22,6 +23,10 @@ export class LinkBox extends React.Component<Props> { onViewButtonPressed = (e: React.PointerEvent): void => { console.log("view down"); e.stopPropagation(); + let docView = DocumentManager.Instance.getDocumentView(this.props.pairedDoc); + if (docView) { + docView.props.focus(this.props.pairedDoc); + } } onEditButtonPressed = (e: React.PointerEvent): void => { |