import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { Tooltip } from "@material-ui/core"; import { action, computed, observable } from "mobx"; import { observer } from "mobx-react"; import { Doc } from "../../../fields/Doc"; import { DateCast, StrCast } from "../../../fields/Types"; import { LinkManager } from "../../util/LinkManager"; import { undoBatch } from "../../util/UndoManager"; import './LinkEditor.scss'; import React = require("react"); interface LinkEditorProps { sourceDoc: Doc; linkDoc: Doc; showLinks: () => void; hideback?: boolean; } @observer export class LinkEditor extends React.Component { @observable description = StrCast(LinkManager.currentLink?.description); @observable relationship = StrCast(LinkManager.currentLink?.linkRelationship); @observable openDropdown: boolean = false; @observable showInfo: boolean = false; @computed get infoIcon() { if (this.showInfo) { return "chevron-up"; } return "chevron-down"; } @observable private buttonColor: string = ""; @observable private relationshipButtonColor: string = ""; //@observable description = this.props.linkDoc.description ? StrCast(this.props.linkDoc.description) : "DESCRIPTION"; @undoBatch deleteLink = (): void => { LinkManager.Instance.deleteLink(this.props.linkDoc); this.props.showLinks(); } @undoBatch setRelationshipValue = action((value: string) => { if (LinkManager.currentLink) { LinkManager.currentLink.linkRelationship = value; this.relationshipButtonColor = "rgb(62, 133, 55)"; setTimeout(action(() => this.relationshipButtonColor = ""), 750); return true; } }); @undoBatch setDescripValue = action((value: string) => { if (LinkManager.currentLink) { LinkManager.currentLink.description = value; this.buttonColor = "rgb(62, 133, 55)"; setTimeout(action(() => this.buttonColor = ""), 750); return true; } }); onKey = (e: React.KeyboardEvent) => { if (e.key === "Enter") { this.setDescripValue(this.description); document.getElementById('input')?.blur(); } } onRelationshipKey = (e: React.KeyboardEvent) => { if (e.key === "Enter") { this.setRelationshipValue(this.relationship); document.getElementById('input')?.blur(); } } onDown = () => this.setDescripValue(this.description); onRelationshipDown = () => this.setRelationshipValue(this.description); @action handleChange = (e: React.ChangeEvent) => { this.description = e.target.value; } @action handleRelationshipChange = (e: React.ChangeEvent) => { this.relationship = e.target.value; } @computed get editRelationship() { return
Link Relationship:
Set
; } @computed get editDescription() { return
Link Description:
Set
; } @action changeDropdown = () => { this.openDropdown = !this.openDropdown; } @undoBatch changeFollowBehavior = action((follow: string) => { this.openDropdown = false; Doc.GetProto(this.props.linkDoc).followLinkLocation = follow; }); @computed get followingDropdown() { return
Follow Behavior:
{StrCast(this.props.linkDoc.followLinkLocation, "default")}
this.changeFollowBehavior("default")}> Default
this.changeFollowBehavior("add:left")}> Always open in new left pane
this.changeFollowBehavior("add:right")}> Always open in new right pane
this.changeFollowBehavior("replace:right")}> Always replace right tab
this.changeFollowBehavior("replace:left")}> Always replace left tab
this.changeFollowBehavior("fullScreen")}> Always open full screen
this.changeFollowBehavior("add")}> Always open in a new tab
this.changeFollowBehavior("replace")}> Replace Tab
{this.props.linkDoc.linksToAnnotation ?
this.changeFollowBehavior("openExternal")}> Always open in external page
: null}
; } @action changeInfo = () => { this.showInfo = !this.showInfo; } render() { const destination = LinkManager.getOppositeAnchor(this.props.linkDoc, this.props.sourceDoc); return !destination ? (null) : (
Return to link menu
} placement="top">

Editing Link to: { destination.proto?.title ?? destination.title ?? "untitled"}

Show more link information
} placement="top">
{this.showInfo ?
{this.props.linkDoc.author ?
Author: {this.props.linkDoc.author}
: null}
{this.props.linkDoc.creationDate ?
Creation Date: {DateCast(this.props.linkDoc.creationDate).toString()}
: null}
: null} {this.editDescription} {this.editRelationship} {this.followingDropdown}
); } }