From 9a93306ba382018ebf3c686117bd4301beda61ef Mon Sep 17 00:00:00 2001 From: madelinegr Date: Wed, 12 Jun 2019 15:33:51 -0400 Subject: BUtton status and pres status saved on refresh, only groups left --- src/client/views/MainView.tsx | 7 ++- .../views/presentationview/PresentationElement.tsx | 42 ++++++++++------ .../views/presentationview/PresentationView.tsx | 57 ++++++++++++++++------ 3 files changed, 73 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/client/views/MainView.tsx b/src/client/views/MainView.tsx index c98e6e8fb..3d772916e 100644 --- a/src/client/views/MainView.tsx +++ b/src/client/views/MainView.tsx @@ -200,12 +200,15 @@ export class MainView extends React.Component { whenActiveChanged={emptyFunction} bringToFront={emptyFunction} ContainingCollectionView={undefined} />; - const pres = mainCont ? FieldValue(Cast(mainCont.presentationView, Doc)) : undefined; + let castRes = mainCont ? FieldValue(Cast(mainCont.presentationView, Doc)) : undefined; + console.log("GETTING mainContent()"); + console.log(castRes instanceof Promise); + console.log(castRes); return {({ measureRef }) =>
{content} - {pres ? : null} + {castRes ? : null}
}
; diff --git a/src/client/views/presentationview/PresentationElement.tsx b/src/client/views/presentationview/PresentationElement.tsx index 7928722f2..9fe69c2e3 100644 --- a/src/client/views/presentationview/PresentationElement.tsx +++ b/src/client/views/presentationview/PresentationElement.tsx @@ -1,9 +1,9 @@ import { observer } from "mobx-react"; import React = require("react"); -import { Doc, DocListCast } from "../../../new_fields/Doc"; +import { Doc, DocListCast, DocListCastAsync } from "../../../new_fields/Doc"; import { NumCast, BoolCast, StrCast, Cast } from "../../../new_fields/Types"; import { Id } from "../../../new_fields/FieldSymbols"; -import { observable, action, computed } from "mobx"; +import { observable, action, computed, runInAction } from "mobx"; import "./PresentationView.scss"; import { Utils } from "../../../Utils"; import { library } from '@fortawesome/fontawesome-svg-core'; @@ -64,21 +64,33 @@ export default class PresentationElement extends React.Component>; - let castedList = DocListCast(this.props.presButtonBackUp.selectedButtonDocs); - if (castedList.length !== 0) { - // this.selectedButtons = castedList; - let selectedButtonOfDoc = Cast(castedList[this.props.index].selectedButtons, listSpec("boolean"), null); + let castedList = Cast(this.props.presButtonBackUp.selectedButtonDocs, listSpec(Doc)); + if (!castedList) { + this.props.presButtonBackUp.selectedButtonDocs = castedList = new List(); + } + // let castedList = DocListCast(this.props.presButtonBackUp.selectedButtonDocs); + + console.log("Mounted!!"); + console.log("CastedList Len: ", castedList.length); + console.log("Index of doc: ", this.props.index); + + if (castedList.length <= this.props.index) { + console.log("Entered here by index : ", this.props.index); + castedList.push(new Doc()); + } else { + let curDoc: Doc = await castedList[this.props.index]; + let selectedButtonOfDoc = Cast(curDoc.selectedButtons, listSpec("boolean"), null); + console.log("Entered First Place"); if (selectedButtonOfDoc !== undefined) { - this.selectedButtons = selectedButtonOfDoc; + runInAction(() => this.selectedButtons = selectedButtonOfDoc); + console.log("Entered Second Place"); } - console.log("Entered!!"); - } - console.log("Mounted!!"); - //this.props.presButtonBackUp.elIndex = this.props.index; + + } /** @@ -195,9 +207,9 @@ export default class PresentationElement extends React.Component { + autoSaveButtonChange = async (index: buttonIndex) => { // let castedList = Cast(this.props.presButtonBackUp.selectedButtons, listSpec(Doc), null) as any as List>; - let castedList = DocListCast(this.props.presButtonBackUp.selectedButtonDocs); + let castedList = (await DocListCastAsync(this.props.presButtonBackUp.selectedButtonDocs))!; castedList[this.props.index].selectedButtons = new List(this.selectedButtons); //this.props.mainDocument.presButtonBackUp = this.props.presButtonBackUp; diff --git a/src/client/views/presentationview/PresentationView.tsx b/src/client/views/presentationview/PresentationView.tsx index 8b0b919fd..b872181ae 100644 --- a/src/client/views/presentationview/PresentationView.tsx +++ b/src/client/views/presentationview/PresentationView.tsx @@ -78,7 +78,7 @@ class PresentationViewList extends React.Component { const children = DocListCast(this.props.Document.data); this.initializeGroupIds(children); this.props.setChildrenDocs(children); - this.initializeSelectedButtonDocs(children); + //this.initializeSelectedButtonDocs(children); return (
@@ -105,23 +105,47 @@ export class PresentationView extends React.Component { @observable presGroupBackUp: Doc = new Doc(); @observable presButtonBackUp: Doc = new Doc(); - @action + + componentDidMount() { - let castedGroupBackUp: Doc = Cast(this.props.Document.presGroupBackUp, Doc, new Doc()); - let castedButtonBackUp: Doc = Cast(this.props.Document.presButtonBackUp, Doc, new Doc()); - // if (castedButtonBackUp === undefined) { - // this.props.Document.presButtonBackUp = new Doc(); - // } else { - this.presButtonBackUp = castedButtonBackUp; - // } - // if (castedGroupBackUp === undefined) { - // this.props.Document.presGroupBackUp = new Doc(); - // } else { - this.presGroupBackUp = castedGroupBackUp; - // - - // } + // let newDoc = new Doc(); + // let newDoc2 = new Doc(); + let castedGroupBackUp = Cast(this.props.Document.presGroupBackUp, Doc); + let castedButtonBackUp = Cast(this.props.Document.presButtonBackUp, Doc); + if (castedGroupBackUp instanceof Promise) { + castedGroupBackUp.then(doc => { + let toAssign = doc ? doc : new Doc(); + this.props.Document.presGroupBackUp = toAssign; + runInAction(() => this.presGroupBackUp = toAssign); + }); + } else { + runInAction(() => { + let toAssign = new Doc(); + this.presGroupBackUp = toAssign; + this.props.Document.presGroupBackUp = toAssign; + + }); + + } + + if (castedButtonBackUp instanceof Promise) { + castedButtonBackUp.then(doc => { + let toAssign = doc ? doc : new Doc(); + this.props.Document.presButtonBackUp = toAssign; + runInAction(() => this.presButtonBackUp = toAssign); + }); + + } else { + runInAction(() => { + let toAssign = new Doc(); + this.presButtonBackUp = toAssign; + this.props.Document.presButtonBackUp = toAssign; + }); + + } + let presStatusBackUp = BoolCast(this.props.Document.presStatus, null); + runInAction(() => this.presStatus = presStatusBackUp); } //observable means render is re-called every time variable is changed @@ -362,6 +386,7 @@ export class PresentationView extends React.Component { this.startPresentation(0); this.gotoDocument(0); } + this.props.Document.presStatus = this.presStatus; } @action -- cgit v1.2.3-70-g09d2