aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/nodes/IconBox.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/views/nodes/IconBox.tsx')
-rw-r--r--src/client/views/nodes/IconBox.tsx53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/client/views/nodes/IconBox.tsx b/src/client/views/nodes/IconBox.tsx
index 9c90c0a0e..19abec4af 100644
--- a/src/client/views/nodes/IconBox.tsx
+++ b/src/client/views/nodes/IconBox.tsx
@@ -2,14 +2,17 @@ import React = require("react");
import { library } from '@fortawesome/fontawesome-svg-core';
import { faCaretUp, faFilePdf, faFilm, faImage, faObjectGroup, faStickyNote } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
-import { action, computed } from "mobx";
+import { computed, observable, runInAction, reaction, IReactionDisposer } from "mobx";
import { observer } from "mobx-react";
-import { Document } from '../../../fields/Document';
-import { IconField } from "../../../fields/IconFIeld";
-import { KeyStore } from "../../../fields/KeyStore";
-import { SelectionManager } from "../../util/SelectionManager";
import { FieldView, FieldViewProps } from './FieldView';
import "./IconBox.scss";
+import { Cast, StrCast, BoolCast } from "../../../new_fields/Types";
+import { Doc, DocListCast } from "../../../new_fields/Doc";
+import { IconField } from "../../../new_fields/IconField";
+import { ContextMenu } from "../ContextMenu";
+import Measure from "react-measure";
+import { MINIMIZED_ICON_SIZE } from "../../views/globalCssVariables.scss";
+import { listSpec } from "../../../new_fields/Schema";
library.add(faCaretUp);
@@ -21,9 +24,19 @@ library.add(faFilm);
@observer
export class IconBox extends React.Component<FieldViewProps> {
public static LayoutString() { return FieldView.LayoutString(IconBox); }
+ _reactionDisposer?: IReactionDisposer;
+ componentDidMount() {
+ this._reactionDisposer = reaction(() => [this.props.Document.maximizedDocs],
+ async () => {
+ let maxDoc = await DocListCast(this.props.Document.maximizedDocs);
+ this.props.Document.title = (maxDoc && maxDoc.length === 1 ? maxDoc[0].title + ".icon" : "");
+ }, { fireImmediately: true });
+ }
+ componentWillUnmount() {
+ if (this._reactionDisposer) this._reactionDisposer();
+ }
- @computed get maximized() { return this.props.Document.GetT(KeyStore.MaximizedDoc, Document); }
- @computed get layout(): string { return this.props.Document.GetData(this.props.fieldKey, IconField, "<p>Error loading layout data</p>" as string); }
+ @computed get layout(): string { const field = Cast(this.props.Document[this.props.fieldKey], IconField); return field ? field.icon : "<p>Error loading icon data</p>"; }
@computed get minimizedIcon() { return IconBox.DocumentIcon(this.layout); }
public static DocumentIcon(layout: string) {
@@ -33,13 +46,35 @@ export class IconBox extends React.Component<FieldViewProps> {
layout.indexOf("Video") !== -1 ? faFilm :
layout.indexOf("Collection") !== -1 ? faObjectGroup :
faCaretUp;
- return <FontAwesomeIcon icon={button} className="documentView-minimizedIcon" />
+ return <FontAwesomeIcon icon={button} className="documentView-minimizedIcon" />;
}
+ setLabelField = (e: React.MouseEvent): void => {
+ this.props.Document.hideLabel = !BoolCast(this.props.Document.hideLabel);
+ }
+
+ specificContextMenu = (e: React.MouseEvent): void => {
+ ContextMenu.Instance.addItem({
+ description: BoolCast(this.props.Document.hideLabel) ? "show label" : "hide label",
+ event: this.setLabelField
+ });
+ }
+ @observable _panelWidth: number = 0;
+ @observable _panelHeight: number = 0;
render() {
+ let labelField = StrCast(this.props.Document.labelField);
+ let hideLabel = BoolCast(this.props.Document.hideLabel);
+ let maxDoc = Cast(this.props.Document.maximizedDocs, listSpec(Doc), []);
+ let firstDoc = maxDoc && maxDoc.length > 0 && maxDoc[0] instanceof Doc ? maxDoc[0] as Doc : undefined;
+ let label = !hideLabel && firstDoc && labelField ? firstDoc[labelField] : "";
return (
- <div className="iconBox-container">
+ <div className="iconBox-container" onContextMenu={this.specificContextMenu}>
{this.minimizedIcon}
+ <Measure onResize={(r) => runInAction(() => { if (r.entry.width || BoolCast(this.props.Document.hideLabel)) this.props.Document.nativeWidth = this.props.Document.width = (r.entry.width + Number(MINIMIZED_ICON_SIZE)); })}>
+ {({ measureRef }) =>
+ <span ref={measureRef} className="iconBox-label">{label}</span>
+ }
+ </Measure>
</div>);
}
} \ No newline at end of file