import * as React from 'react'; import './CalendarManager.scss'; import { observer } from "mobx-react"; import { action, computed, observable, runInAction } from 'mobx'; import { Doc } from '../../fields/Doc'; import { DocumentView } from '../views/nodes/DocumentView'; import { DictationOverlay } from '../views/DictationOverlay'; import { TaskCompletionBox } from '../views/nodes/TaskCompletedBox'; import { MainViewModal } from '../views/MainViewModal'; import { TextField } from '@material-ui/core'; import Select from 'react-select'; import { SettingsManager } from './SettingsManager'; import { StrCast } from '../../fields/Types'; import { SelectionManager } from './SelectionManager'; import { DocumentManager } from './DocumentManager'; import { DocData } from '../../fields/DocSymbols'; import { DateRange, Range, RangeKeyDict } from 'react-date-range'; import { Button } from 'browndash-components'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { IconLookup, faPlus } from '@fortawesome/free-solid-svg-icons'; import 'react-date-range/dist/styles.css'; import 'react-date-range/dist/theme/default.css'; type CreationType = 'new-calendar' | 'existing-calendar' | 'manage-calendars'; @observer export class CalendarManager extends React.Component<{}> { public static Instance: CalendarManager; @observable private isOpen = false; @observable private targetDoc: Doc | undefined; // the target document @observable private targetDocView: DocumentView | undefined; // the DocumentView of the target doc @observable private dialogueBoxOpacity = 1; // for the modal @observable private overlayOpacity = 0.4; // for the modal @observable private layoutDocAcls: boolean = false; // whether the layout doc or data doc's acls are to be used @observable private creationType: CreationType = 'new-calendar'; @observable calendarName: string = ""; @action setInterationType = (type: CreationType) => { this.creationType = type; } public open = (target?: DocumentView, target_doc?: Doc) => { console.log('hi'); runInAction(() => { this.targetDoc = target_doc || target?.props.Document; this.targetDocView = target; DictationOverlay.Instance.hasActiveModal = true; this.isOpen = this.targetDoc !== undefined; }) }; public close = action(() => { this.isOpen = false; TaskCompletionBox.taskCompleted = false; setTimeout( action(() => { DictationOverlay.Instance.hasActiveModal = false; this.targetDoc = undefined; }), 500 ); this.layoutDocAcls = false; }); constructor(props: {}) { super(props); CalendarManager.Instance = this; } componentDidMount(): void { } private focusOn = (contents: string) => { const title = this.targetDoc ? StrCast(this.targetDoc.title) : ''; const docs = SelectionManager.Views().length > 1 ? SelectionManager.Views().map(docView => docView.props.Document) : [this.targetDoc]; return ( { if (this.targetDoc && this.targetDocView && docs.length === 1) { DocumentManager.Instance.showDocument(this.targetDoc, { willZoomCentered: true }); } }} onPointerEnter={action(() => { if (docs.length) { docs.forEach(doc => doc && Doc.BrushDoc(doc)); this.dialogueBoxOpacity = 0.1; this.overlayOpacity = 0.1; } })} onPointerLeave={action(() => { if (docs.length) { docs.forEach(doc => doc && Doc.UnBrushDoc(doc)); this.dialogueBoxOpacity = 1; this.overlayOpacity = 0.4; } })}> {contents} ); }; @observable selectedDateRange: Range[] = [{ startDate: new Date(), endDate: undefined, key: 'selection' }] @action setSelectedDateRange = (range: Range[]) => { this.selectedDateRange = range; } @computed get createButtonActive() { if (this.calendarName.length === 0) return false // disabled if no calendar name let startDate: Date | undefined; let endDate: Date | undefined; try { startDate = this.selectedDateRange[0].startDate; endDate = this.selectedDateRange[0].endDate; } catch (e: any){ return false; // disabled } if (!startDate || !endDate) return false; // disabled if any is undefined return true; } @computed get calendarInterface(){ let docs = SelectionManager.Views().length < 2 ? [this.targetDoc] : SelectionManager.Views().map(docView => docView.rootDoc); const targetDoc = this.layoutDocAcls ? docs[0] : docs[0]?.[DocData]; const currentDate = new Date(); return (
{this.focusOn(docs.length < 2 ? StrCast(targetDoc?.title, 'this document') : '-multiple-')}