aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/LinkMenu.tsx
blob: 9a95a4f09c8ed0a9002356b725da7b41950dfc42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { observable, computed, action } from "mobx";
import React = require("react");
import { SelectionManager } from "../../util/SelectionManager";
import { observer } from "mobx-react";
import './LinkMenu.scss'
import { KeyStore } from '../../../fields/KeyStore'
import { props } from "bluebird";
import { DocumentView } from "./DocumentView";
import { LinkBox } from "./LinkBox"
import { Document } from "../../../fields/Document";
import { ListField } from "../../../fields/ListField";
import { TextField } from "../../../fields/TextField";
import { FieldWaiting } from "../../../fields/Field";
import { LinkEditor } from "./LinkEditor";

interface Props {
    docView: DocumentView;
    changeFlyout: () => void
}

@observer
export class LinkMenu extends React.Component<Props> {

    @observable private _editingLink?: Document;

    render() {
        //get list of links from document
        let linkFrom: Document[] = this.props.docView.props.Document.GetData(KeyStore.LinkedFromDocs, ListField, []);
        let linkTo: Document[] = this.props.docView.props.Document.GetData(KeyStore.LinkedToDocs, ListField, []);
        if (this._editingLink === undefined) {
            return (

                <div id="menu-container">
                    <input id="search-bar" type="text" placeholder="Search..."></input>
                    <div id="link-list">

                        {linkTo.map(link => {
                            let name = link.GetData(KeyStore.Title, TextField, new String);
                            let doc = link.GetT(KeyStore.LinkedToDocs, Document);
                            if (doc && doc != FieldWaiting) {
                                return <LinkBox linkDoc={link} linkName={name} pairedDoc={doc} showEditor={action(() => this._editingLink = link)} type={"Destination: "} />
                            } else {
                                return <div></div>
                            }

                        })}

                        {linkFrom.map(link => {
                            let name = link.GetData(KeyStore.Title, TextField, new String);
                            let doc = link.GetT(KeyStore.LinkedFromDocs, Document);
                            if (doc && doc != FieldWaiting) {
                                return <LinkBox linkDoc={link} linkName={name} pairedDoc={doc} showEditor={action(() => this._editingLink = link)} type={"Source: "} />
                            } else {
                                return <div></div>
                            }
                        })}
                    </div>

                </div>
            )
        } else {
            return (
                <LinkEditor linkDoc={this._editingLink} showLinks={action(() => this._editingLink = undefined)}></LinkEditor>
            )
        }

    }
}