diff options
author | bob <bcz@cs.brown.edu> | 2019-02-06 09:44:45 -0500 |
---|---|---|
committer | bob <bcz@cs.brown.edu> | 2019-02-06 09:44:45 -0500 |
commit | 7598b88bbad9690c59f8b164144aa0d02a0a211f (patch) | |
tree | a05c7f0884139af014daae0cae09ba2e852d90ef /src/views/nodes/ImageBox.tsx | |
parent | e59dbb02175ec394a35c496201da71c90cd6a50a (diff) |
working stub version
Diffstat (limited to 'src/views/nodes/ImageBox.tsx')
-rw-r--r-- | src/views/nodes/ImageBox.tsx | 46 |
1 files changed, 19 insertions, 27 deletions
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} > |