diff options
author | madelinegr <mgriswold99@gmail.com> | 2019-02-12 18:55:11 -0500 |
---|---|---|
committer | madelinegr <mgriswold99@gmail.com> | 2019-02-12 18:55:11 -0500 |
commit | 1d667d19f5402dc9f9069e0a57008dac96f6de2a (patch) | |
tree | 59572ebc84ae0dea9780c96a6d43a811a21fed10 /src/client/views/nodes/WebBox.tsx | |
parent | 7a93f60c9529e5d175e617fc7c07145a9b33e572 (diff) |
set up web box classes
Diffstat (limited to 'src/client/views/nodes/WebBox.tsx')
-rw-r--r-- | src/client/views/nodes/WebBox.tsx | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/client/views/nodes/WebBox.tsx b/src/client/views/nodes/WebBox.tsx new file mode 100644 index 000000000..f50f8c60e --- /dev/null +++ b/src/client/views/nodes/WebBox.tsx @@ -0,0 +1,73 @@ + +import Lightbox from 'react-image-lightbox'; +import { SelectionManager } from "../../util/SelectionManager"; +import "./WebBox.scss"; +import React = require("react") +import { WebField } from '../../../fields/WebField'; +import { FieldViewProps, FieldView } from './FieldView'; +import { CollectionFreeFormDocumentView } from './CollectionFreeFormDocumentView'; +import { FieldWaiting } from '../../../fields/Field'; +import { observer } from "mobx-react" +import { observable, action, spy } from 'mobx'; +import { KeyStore } from '../../../fields/Key'; + +@observer +export class WebBox extends React.Component<FieldViewProps> { + + public static LayoutString() { return FieldView.LayoutString("WebBox"); } + private _ref: React.RefObject<HTMLDivElement>; + private _downX: number = 0; + private _downY: number = 0; + private _lastTap: number = 0; + @observable private _isOpen: boolean = false; + + constructor(props: FieldViewProps) { + super(props); + + this._ref = React.createRef(); + this.state = { + isOpen: false, + }; + } + + componentDidMount() { + } + + componentWillUnmount() { + } + + onPointerDown = (e: React.PointerEvent): void => { + if (Date.now() - this._lastTap < 300) { + if (e.buttons === 1 && this.props.DocumentViewForField instanceof CollectionFreeFormDocumentView && + SelectionManager.IsSelected(this.props.DocumentViewForField)) { + e.stopPropagation(); + this._downX = e.clientX; + this._downY = e.clientY; + document.removeEventListener("pointerup", this.onPointerUp); + document.addEventListener("pointerup", this.onPointerUp); + } + } else { + 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._isOpen = true; + } + e.stopPropagation(); + } + + render() { + let field = this.props.doc.Get(this.props.fieldKey); + let path = field == FieldWaiting ? "https://image.flaticon.com/icons/svg/66/66163.svg" : + field instanceof WebField ? field.Data.href : "https://cs.brown.edu/"; + let nativeWidth = this.props.doc.GetNumber(KeyStore.NativeWidth, 1); + + return ( + <div className="webBox-cont" onPointerDown={this.onPointerDown} ref={this._ref} > + <iframe src={path} width={nativeWidth}></iframe> + </div>) + } +}
\ No newline at end of file |