aboutsummaryrefslogtreecommitdiff
path: root/src/views
diff options
context:
space:
mode:
authorbob <bcz@cs.brown.edu>2019-02-06 09:44:45 -0500
committerbob <bcz@cs.brown.edu>2019-02-06 09:44:45 -0500
commit7598b88bbad9690c59f8b164144aa0d02a0a211f (patch)
treea05c7f0884139af014daae0cae09ba2e852d90ef /src/views
parente59dbb02175ec394a35c496201da71c90cd6a50a (diff)
working stub version
Diffstat (limited to 'src/views')
-rw-r--r--src/views/nodes/CollectionFreeFormDocumentView.tsx1
-rw-r--r--src/views/nodes/DocumentView.tsx6
-rw-r--r--src/views/nodes/FormattedTextBox.tsx4
-rw-r--r--src/views/nodes/ImageBox.tsx46
4 files changed, 24 insertions, 33 deletions
diff --git a/src/views/nodes/CollectionFreeFormDocumentView.tsx b/src/views/nodes/CollectionFreeFormDocumentView.tsx
index 06ea0c64b..d98c8dcb7 100644
--- a/src/views/nodes/CollectionFreeFormDocumentView.tsx
+++ b/src/views/nodes/CollectionFreeFormDocumentView.tsx
@@ -207,7 +207,6 @@ export class CollectionFreeFormDocumentView extends DocumentView {
render() {
var freestyling = this.props.ContainingCollectionView instanceof CollectionFreeFormView;
- console.log("CollectionFFDocView " + this.props.Document.Title);
return (
<div className="node" ref={this._mainCont} style={{
transform: freestyling ? this.transform : "",
diff --git a/src/views/nodes/DocumentView.tsx b/src/views/nodes/DocumentView.tsx
index 69184cf16..cfd894a38 100644
--- a/src/views/nodes/DocumentView.tsx
+++ b/src/views/nodes/DocumentView.tsx
@@ -129,17 +129,15 @@ export class DocumentView extends React.Component<DocumentViewProps> {
render() {
let bindings = { ...this.props } as any;
for (const key of this.layoutKeys) {
- //let val = this.props.Document.GetField(key); // bcz: ARGH! Why do I need to call this here? (e.g., it's needed and used in ImageBox- shouldn't that trigger a re-render?)
- bindings[key.Name + "Key"] = key;
+ bindings[key.Name + "Key"] = key; // this maps string values of the form <keyname>Key to an actual key Kestore.keyname e.g, "DataKey" => KeyStore.Data
}
for (const key of this.layoutFields) {
let field = this.props.Document.GetField(key);
bindings[key.Name] = field && field != WAITING ? field.GetValue() : field;
}
if (bindings.DocumentView === undefined) {
- bindings.DocumentView = this;
+ bindings.DocumentView = this; // set the DocumentView to this if it hasn't already been set by a sub-class during its render method.
}
- console.log("DocumentView Rendering " + this.props.Document.Title);
return (
<div className="node" ref={this._mainCont} style={{ width: "100%", height: "100%", }}>
<JsxParser
diff --git a/src/views/nodes/FormattedTextBox.tsx b/src/views/nodes/FormattedTextBox.tsx
index f0385c096..cf6a1181a 100644
--- a/src/views/nodes/FormattedTextBox.tsx
+++ b/src/views/nodes/FormattedTextBox.tsx
@@ -1,4 +1,5 @@
import { action, IReactionDisposer, reaction } from "mobx";
+import { observer } from "mobx-react"
import { baseKeymap } from "prosemirror-commands";
import { history, redo, undo } from "prosemirror-history";
import { keymap } from "prosemirror-keymap";
@@ -29,7 +30,8 @@ import { CollectionFreeFormDocumentView } from "./CollectionFreeFormDocumentView
// When rendered() by React, this extracts the TextController from the Document stored at the
// specified Key and assigns it to an HTML input node. When changes are made tot his node,
// this will edit the document and assign the new value to that field.
-//
+//]
+@observer
export class FormattedTextBox extends React.Component<FieldViewProps> {
public static LayoutString() { return FieldView.LayoutString("FormattedTextBox"); }
diff --git a/src/views/nodes/ImageBox.tsx b/src/views/nodes/ImageBox.tsx
index 9b086d373..079cca8ab 100644
--- a/src/views/nodes/ImageBox.tsx
+++ b/src/views/nodes/ImageBox.tsx
@@ -8,20 +8,19 @@ import { ImageField } from '../../fields/ImageField';
import { FieldViewProps, FieldView } from './FieldView';
import { CollectionFreeFormDocumentView } from './CollectionFreeFormDocumentView';
import { WAITING } from '../../fields/Field';
-import { Key, KeyStore } from '../../fields/Key';
+import { observer } from "mobx-react"
+import { observable, action } from 'mobx';
-interface ImageBoxState {
- photoIndex: number,
- isOpen: boolean,
-};
+@observer
+export class ImageBox extends React.Component<FieldViewProps> {
-export class ImageBox extends React.Component<FieldViewProps, ImageBoxState> {
-
- public static LayoutString() { return FieldView.LayoutString("ImageBox DataVal={Data} "); }
+ public static LayoutString() { return FieldView.LayoutString("ImageBox"); }
private _ref: React.RefObject<HTMLDivElement>;
private _downX: number = 0;
private _downY: number = 0;
private _lastTap: number = 0;
+ @observable private _photoIndex: number = 0;
+ @observable private _isOpen: boolean = false;
constructor(props: FieldViewProps) {
super(props);
@@ -52,44 +51,37 @@ export class ImageBox extends React.Component<FieldViewProps, ImageBoxState> {
this._lastTap = Date.now();
}
}
+ @action
onPointerUp = (e: PointerEvent): void => {
document.removeEventListener("pointerup", this.onPointerUp);
if (Math.abs(e.clientX - this._downX) < 2 && Math.abs(e.clientY - this._downY) < 2) {
- this.setState({ isOpen: true })
+ this._isOpen = true;
}
e.stopPropagation();
}
lightbox = (path: string) => {
const images = [path, "http://www.cs.brown.edu/~bcz/face.gif"];
- const { photoIndex } = this.state;
- if (this.state.isOpen && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView && SelectionManager.IsSelected(this.props.DocumentViewForField)) {
+ if (this._isOpen && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView && SelectionManager.IsSelected(this.props.DocumentViewForField)) {
return (<Lightbox
- mainSrc={images[photoIndex]}
- nextSrc={images[(photoIndex + 1) % images.length]}
- prevSrc={images[(photoIndex + images.length - 1) % images.length]}
+ mainSrc={images[this._photoIndex]}
+ nextSrc={images[(this._photoIndex + 1) % images.length]}
+ prevSrc={images[(this._photoIndex + images.length - 1) % images.length]}
onCloseRequest={() => this.setState({ isOpen: false })}
- onMovePrevRequest={() =>
- this.setState({ photoIndex: (photoIndex + images.length - 1) % images.length, })
- }
- onMoveNextRequest={() =>
- this.setState({ photoIndex: (photoIndex + 1) % images.length, })
- }
+ onMovePrevRequest={action(() =>
+ this._photoIndex = (this._photoIndex + images.length - 1) % images.length
+ )}
+ onMoveNextRequest={action(() =>
+ this._photoIndex = (this._photoIndex + 1) % images.length
+ )}
/>)
}
}
render() {
-
- // bcz: use LayoutFields (here) or LayoutKeys (below)?
- // let field = (this.props as any).DataVal;//this.props.doc.GetFieldT(this.props.fieldKey, ImageField);
- // let path = field == WAITING ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
- // field instanceof URL ? field.href : "";
-
let field = this.props.doc.GetFieldT(this.props.fieldKey, ImageField);
let path = field == WAITING ? "https://image.flaticon.com/icons/svg/66/66163.svg" :
field instanceof ImageField ? field.Data.href : "";
- console.log("ImageBox Rendering " + this.props.doc.Title);
return (
<div className="imageBox-cont" onPointerDown={this.onPointerDown} ref={this._ref} >