diff options
author | alinayejin <alina_kim@brown.edu> | 2023-12-06 23:40:54 -0500 |
---|---|---|
committer | alinayejin <alina_kim@brown.edu> | 2023-12-06 23:40:54 -0500 |
commit | 04d6da65b5e75b9a67c0f5722b1af9b9ea9500d1 (patch) | |
tree | 4cc82071a7932fa606519b600d5ce92f7bea7115 | |
parent | 41d5ef99eaa30afe59b15e0c8c7f3f3bed57d33d (diff) | |
parent | 94cefea3f6c3999b0364b22a81ade49e28135011 (diff) |
Merge branch 'info-ui' of https://github.com/brown-dash/Dash-Web into info-ui
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoState.tsx | 13 | ||||
-rw-r--r-- | src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoUI.tsx | 79 |
2 files changed, 58 insertions, 34 deletions
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoState.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoState.tsx index 3c19ef4e9..9090d0ea5 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoState.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoState.tsx @@ -3,10 +3,13 @@ import { observer } from 'mobx-react'; import './CollectionFreeFormView.scss'; import React = require('react'); +export type infoArc = { + events: () => any; + actions: (arg?: any) => any; +}; export type infoState = { Message: string; - Events: () => any; - Actions: (arg?: any) => any; + Arcs: infoArc[]; }; export interface CollectionFreeFormInfoStateProps { @@ -15,10 +18,10 @@ export interface CollectionFreeFormInfoStateProps { @observer export class CollectionFreeFormInfoState extends React.Component<CollectionFreeFormInfoStateProps> { - _disposer: IReactionDisposer | undefined; + _disposers: IReactionDisposer[] = []; - clearState = () => this._disposer?.(); - initState = () => (this._disposer = reaction(this.props.state.Events, this.props.state.Actions, { fireImmediately: true })); + clearState = () => this._disposers.map(disposer => disposer()); + initState = () => (this._disposers = this.props.state.Arcs.map(arc => reaction(arc.events, arc.actions, { fireImmediately: true }))); componentDidMount(): void { this.initState(); diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoUI.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoUI.tsx index 74b5545bd..a54ee4b2c 100644 --- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoUI.tsx +++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoUI.tsx @@ -25,54 +25,75 @@ export class CollectionFreeFormInfoUI extends React.Component<CollectionFreeForm constructor(props: any) { super(props); - this.currState = this.start; + this.currState = this.state0; } - @observable currState: infoState; - @computed get first_doc() { return this.props.Freeform.childDocs.lastElement(); } - start: infoState = { + @observable currState: infoState; + state0: infoState = { Message: 'Click to create Object', - Events: () => this.props.Freeform.childDocs, - Actions: (docs: Doc[]) => { - if (docs.length === 1) this.currState = this.state1; - if (docs.length > 1) this.currState = this.state2; - }, + Arcs: [ + { + events: () => this.props.Freeform.childDocs, + actions: (docs: Doc[]) => { + if (docs.length === 1) this.currState = this.state1; + if (docs.length > 1) this.currState = this.state2; + }, + }, + ], }; state1: infoState = { Message: 'Create a second doc', - Events: () => this.props.Freeform.childDocs, - Actions: (docs: Doc[]) => { - if (docs.length === 0) this.currState = this.start; - if (docs.length === 2) this.currState = this.state2; - }, + Arcs: [ + { + events: () => this.props.Freeform.childDocs, + actions: (docs: Doc[]) => { + if (docs.length === 0) this.currState = this.state0; + if (docs.length === 2) this.currState = this.state2; + }, + }, + ], }; state2: infoState = { Message: 'Create a link', - Events: () => ({ links: this.first_doc && LinkManager.Instance.getAllDirectLinks(this.first_doc), docs: this.props.Freeform.childDocs.slice() }), - Actions: arc => { - const { links, docs } = arc; - if (docs.length === 0) this.currState = this.start; - if (docs.length === 1) this.currState = this.state1; - if (links?.length) this.currState = this.state3; - }, + Arcs: [ + { + events: () => this.first_doc && LinkManager.Instance.getAllDirectLinks(this.first_doc), + actions: links => links?.length && (this.currState = this.state3), + }, + { + events: () => this.props.Freeform.childDocs, + actions: docs => { + if (docs.length === 0) this.currState = this.state0; + if (docs.length === 1) this.currState = this.state1; + }, + }, + ], }; state3: infoState = { Message: 'View links', - Events: () => ({ links: this.first_doc && LinkManager.Instance.getAllDirectLinks(this.first_doc), viewingLinks: DocumentLinksButton.LinkEditorDocView }), - Actions: arc => { - const { links, viewingLinks } = arc; - if (viewingLinks) this.currState = this.state4; - if (links?.length === 0) this.currState = this.state2; - }, + Arcs: [ + { + events: () => this.first_doc && LinkManager.Instance.getAllDirectLinks(this.first_doc), + actions: links => links?.length === 0 && (this.currState = this.state2), + }, + { + events: () => DocumentLinksButton.LinkEditorDocView, + actions: viewingLinks => viewingLinks && (this.currState = this.state4), + }, + ], }; state4: infoState = { Message: 'You did it!', - Events: () => false, - Actions: arc => {}, + Arcs: [ + { + events: () => false, + actions: arc => {}, + }, + ], }; /* |