import React = require('react');
import { observer } from 'mobx-react';
import { computed, action, observable } from 'mobx';
import { CurrentUserUtils } from '../server/authentication/models/current_user_utils';
import { FieldValue, Cast, StrCast } from '../new_fields/Types';
import { Doc } from '../new_fields/Doc';
import { Docs } from '../client/documents/Documents';
import { CollectionView } from '../client/views/collections/CollectionView';
import { DocumentView } from '../client/views/nodes/DocumentView';
import { emptyPath, emptyFunction, returnFalse, returnOne, returnEmptyString, returnTrue } from '../Utils';
import { Transform } from '../client/util/Transform';
import { library } from '@fortawesome/fontawesome-svg-core';
import { faPenNib, faHighlighter, faEraser, faMousePointer, faBreadSlice, faTrash, faCheck, faLongArrowAltLeft } from '@fortawesome/free-solid-svg-icons';
import { Scripting } from '../client/util/Scripting';
import { CollectionFreeFormView } from '../client/views/collections/collectionFreeForm/CollectionFreeFormView';
import GestureOverlay from '../client/views/GestureOverlay';
import { InkingControl } from '../client/views/InkingControl';
import { InkTool } from '../new_fields/InkField';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import "./MobileInterface.scss";
import { SelectionManager } from '../client/util/SelectionManager';
import { DateField } from '../new_fields/DateField';
import { GestureUtils } from '../pen-gestures/GestureUtils';
import { DocServer } from '../client/DocServer';
library.add(faLongArrowAltLeft);
@observer
export default class MobileInterface extends React.Component {
@observable static Instance: MobileInterface;
@computed private get userDoc() { return CurrentUserUtils.UserDocument; }
@computed private get mainContainer() { return this.userDoc ? FieldValue(Cast(this.userDoc.activeMobile, Doc)) : CurrentUserUtils.GuestMobile; }
// @observable private currentView: "main" | "ink" | "upload" = "main";
private mainDoc: Doc = CurrentUserUtils.setupMobileDoc(this.userDoc);
@observable private renderView?: () => JSX.Element;
// private inkDoc?: Doc;
public drawingInk: boolean = false;
// private uploadDoc?: Doc;
constructor(props: Readonly<{}>) {
super(props);
MobileInterface.Instance = this;
}
@action
componentDidMount = () => {
library.add(...[faPenNib, faHighlighter, faEraser, faMousePointer]);
if (this.userDoc && !this.mainContainer) {
// const doc = CurrentUserUtils.setupMobileDoc(this.userDoc);
this.userDoc.activeMobile = this.mainDoc;
}
}
@action
switchCurrentView = (doc: (userDoc: Doc) => Doc, renderView?: () => JSX.Element, onSwitch?: () => void) => {
if (!this.userDoc) return;
this.userDoc.activeMobile = doc(this.userDoc);
onSwitch && onSwitch();
this.renderView = renderView;
console.log("switching current view", renderView);
}
onSwitchInking = () => {
InkingControl.Instance.switchTool(InkTool.Pen);
MobileInterface.Instance.drawingInk = true;
DocServer.Mobile.dispatchOverlayTrigger({
enableOverlay: true,
width: window.innerWidth,
height: window.innerHeight
});
}
// @action
// switchCurrentView = (view: "main" | "ink" | "upload") => {
// this.currentView = view;
// if (this.userDoc) {
// switch (view) {
// case "main": {
// // const doc = CurrentUserUtils.setupMobileDoc(this.userDoc);
// this.userDoc.activeMobile = this.mainDoc;
// break;
// }
// case "ink": {
// this.inkDoc = CurrentUserUtils.setupMobileInkingDoc(this.userDoc);
// this.userDoc.activeMobile = this.inkDoc;
// InkingControl.Instance.switchTool(InkTool.Pen);
// this.drawingInk = true;
// DocServer.Mobile.dispatchOverlayTrigger({
// enableOverlay: true,
// width: window.innerWidth,
// height: window.innerHeight
// });
// break;
// }
// case "upload": {
// this.uploadDoc = CurrentUserUtils.setupMobileUploadDoc(this.userDoc);
// this.userDoc.activeMobile = this.uploadDoc;
// }
// }
// }
// }
renderDefaultContent = () => {
console.log("rendering default content");
if (this.mainContainer) {
return