aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/LinkMenu.tsx
diff options
context:
space:
mode:
authorFawn <fangrui_tong@brown.edu>2019-06-14 15:24:35 -0400
committerFawn <fangrui_tong@brown.edu>2019-06-14 15:24:35 -0400
commitf54496c7aa930e385e77aaf37df8d51db733e3a2 (patch)
tree6c96d5fe127bf65888511d2529fa2e7f8dc1e385 /src/client/views/nodes/LinkMenu.tsx
parent8bcd3567df7c49523638f0b935ecd09b1acad45d (diff)
cleaned up link code
Diffstat (limited to 'src/client/views/nodes/LinkMenu.tsx')
-rw-r--r--src/client/views/nodes/LinkMenu.tsx54
1 files changed, 17 insertions, 37 deletions
diff --git a/src/client/views/nodes/LinkMenu.tsx b/src/client/views/nodes/LinkMenu.tsx
index 47bd6c3eb..ebca54c92 100644
--- a/src/client/views/nodes/LinkMenu.tsx
+++ b/src/client/views/nodes/LinkMenu.tsx
@@ -6,12 +6,8 @@ import { LinkEditor } from "./LinkEditor";
import './LinkMenu.scss';
import React = require("react");
import { Doc, DocListCast } from "../../../new_fields/Doc";
-import { Cast, FieldValue, StrCast } from "../../../new_fields/Types";
import { Id } from "../../../new_fields/FieldSymbols";
import { LinkManager, LinkUtils } from "../../util/LinkManager";
-import { number, string } from "prop-types";
-import { listSpec } from "../../../new_fields/Schema";
-import { Utils } from "../../../Utils";
interface Props {
docView: DocumentView;
@@ -23,57 +19,42 @@ export class LinkMenu extends React.Component<Props> {
@observable private _editingLink?: Doc;
- // renderLinkItems(links: Doc[], key: string, type: string) {
- // return links.map(link => {
- // let doc = FieldValue(Cast(link[key], Doc));
- // if (doc) {
- // return <LinkBox key={doc[Id]} linkDoc={link} linkName={StrCast(link.title)} pairedDoc={doc} showEditor={action(() => this._editingLink = link)} type={type} />;
- // }
- // });
- // }
-
- renderGroup(links: Doc[]) {
+ renderGroup = (group: Doc[]): Array<JSX.Element> => {
let source = this.props.docView.Document;
- return links.map(link => {
- let destination = LinkUtils.findOppositeAnchor(link, source);
- let doc = FieldValue(Cast(destination, Doc));
- if (doc) {
- return <LinkBox key={doc[Id] + source[Id]} linkDoc={link} linkName={StrCast(destination.title)} pairedDoc={doc} showEditor={action(() => this._editingLink = link)} type={""} />;
- }
+ return group.map(linkDoc => {
+ let destination = LinkUtils.findOppositeAnchor(linkDoc, source);
+ return <LinkBox key={destination[Id] + source[Id]} linkDoc={linkDoc} sourceDoc={source} destinationDoc={destination} showEditor={action(() => this._editingLink = linkDoc)} />;
});
}
- renderLinks = (links: Map<string, Array<Doc>>): Array<JSX.Element> => {
+ renderAllGroups = (groups: Map<string, Array<Doc>>): Array<JSX.Element> => {
let linkItems: Array<JSX.Element> = [];
-
- links.forEach((links, group) => {
+ groups.forEach((group, groupType) => {
linkItems.push(
- <div key={group} className="link-menu-group">
- <p className="link-menu-group-name">{group}:</p>
+ <div key={groupType} className="link-menu-group">
+ <p className="link-menu-group-name">{groupType}:</p>
<div className="link-menu-group-wrapper">
- {this.renderGroup(links)}
+ {this.renderGroup(group)}
</div>
</div>
- )
+ );
});
- if (linkItems.length === 0) {
- linkItems.push(<p key="">no links have been created yet</p>);
- }
+ // source doc has no links
+ if (linkItems.length === 0) linkItems.push(<p key="">No links have been created yet. Drag the linking button onto another document to create a link.</p>);
return linkItems;
}
render() {
- let related: Map<string, Doc[]> = LinkManager.Instance.findRelatedGroupedLinks(this.props.docView.props.Document);
+ let sourceDoc = this.props.docView.props.Document;
+ let groups: Map<string, Doc[]> = LinkManager.Instance.findRelatedGroupedLinks(sourceDoc);
if (this._editingLink === undefined) {
return (
- <div id="linkMenu-container">
+ <div className="linkMenu">
{/* <input id="linkMenu-searchBar" type="text" placeholder="Search..."></input> */}
- <div id="linkMenu-list">
- {/* {this.renderLinkItems(linkTo, "linkedTo", "Destination: ")}
- {this.renderLinkItems(linkFrom, "linkedFrom", "Source: ")} */}
- {this.renderLinks(related)}
+ <div className="linkMenu-list">
+ {this.renderAllGroups(groups)}
</div>
</div>
);
@@ -82,6 +63,5 @@ export class LinkMenu extends React.Component<Props> {
<LinkEditor sourceDoc={this.props.docView.props.Document} linkDoc={this._editingLink} showLinks={action(() => this._editingLink = undefined)}></LinkEditor>
);
}
-
}
} \ No newline at end of file