aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/collections/collectionFreeForm/CollectionFreeFormInfoUI.tsx
blob: 147c900befc155344efa75d5ca91d3e487ad8723 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
import { action, makeObservable, observable, runInAction } from 'mobx';
import { observer } from 'mobx-react';
import * as React from 'react';
import { CollectionFreeFormView } from '.';
import { Doc, DocListCast } from '../../../../fields/Doc';
import { InkTool } from '../../../../fields/InkField';
import { DocButtonState, DocumentLinksButton } from '../../nodes/DocumentLinksButton';
import { ButtonType } from '../../nodes/FontIconBox/FontIconBox';
import { ObservableReactComponent } from '../../ObservableReactComponent';
import { CollectionFreeFormInfoState, InfoButton, infoState, InfoState } from './CollectionFreeFormInfoState';

export interface CollectionFreeFormInfoUIProps {
    Document: Doc;
    LayoutDoc: Doc;
    childDocs: () => Doc[];
    close: () => void;
}

@observer
export class CollectionFreeFormInfoUI extends ObservableReactComponent<CollectionFreeFormInfoUIProps> {
    private _originalBackground: string | undefined;
    private _tutorialStates: { [key: string]: infoState } = {};

    public static Init() {
        CollectionFreeFormView.SetInfoUICreator((doc: Doc, layout: Doc, childDocs: () => Doc[], close: () => void) => <CollectionFreeFormInfoUI Document={doc} LayoutDoc={layout} childDocs={childDocs} close={close} />);
    }

    constructor(props: CollectionFreeFormInfoUIProps) {
        super(props);
        makeObservable(this);
        this._tutorialStates = {}; // Initialize an empty object
        this.currState = this.setupStates(); // Call setupStates() here
    }

    @observable _currState: infoState | undefined = undefined;
    @observable _nextState: infoState | undefined = undefined; // Track next state

    get currState() {
        return this._currState;
    }

    set currState(val) {
        runInAction(() => (this._currState = val));
    }

    componentWillUnmount() {
        this._props.Document.backgroundColor = this._originalBackground;
    }

    skipToState = action((newState: infoState) => (this._currState = newState));

    createNextButton = (newState: ReturnType<typeof InfoState>) => {
        return {
            title: 'Next',
            toolTip: 'Next',
            btnType: ButtonType.ClickButton,
            scripts: {
                onClick: `this.skipToState(${newState})`,
            },
            targetState: newState,
        };
    };

    setupStates = () => {
        let docCounter = this._props.childDocs().length;
        let lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
        let linkCounter = Doc.Links(lastDocCreated)?.length;
        let presentationCounter = DocListCast(Doc.ActivePresentation?.data).length;
        this._originalBackground = this._props.Document.backgroundColor as string;

        this._tutorialStates.multipleDocs = InfoState(
            "Let's create a new link! Click the link icon on one document and connect it to another.",
            {
                linkStarted: [
                    () => DocumentLinksButton.StartLink,
                    () => {
                        linkCounter = Doc.Links(lastDocCreated).length;
                        // eslint-disable-next-line no-use-before-define
                        return startedLink;
                    },
                ],
                // docCreated: [() => this._props.childDocs().length > docCounter, () => {
                //     docCounter += 1
                //     lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1]
                //     // eslint-disable-next-line no-use-before-define
                // return this.tutorialStates.makePresentation}]
            },
            'dash-create-link-board.gif'
        );

        this._tutorialStates.presentDocs = InfoState(
            "Select a document then click the 'pin' button in the top left to create your presentation.",
            {
                docPinned: [
                    () => DocListCast(Doc.ActivePresentation?.data).length > presentationCounter,
                    () => {
                        presentationCounter++;
                        // eslint-disable-next-line no-use-before-define
                        return pinnedDoc;
                    },
                ],
            },
            'pin-explanation.gif'
        );

        this._tutorialStates.nestedCollections = InfoState(
            "Want to learn how to create a nested collection? Click the : button and add a 'collection' doc",
            {
                docCreated: [
                    () => this._props.childDocs().length > docCounter,
                    () => {
                        docCounter += 1;
                        lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
                        // eslint-disable-next-line no-use-before-define
                        return marqueeSelection;
                    },
                ],
            },
            'dash-nested-collection.gif'
        );

        this._tutorialStates.makePresentation = InfoState('Add a new document to create a presentation!', {
            docCreated: [
                () => this._props.childDocs().length > docCounter,
                () => {
                    docCounter += 1;
                    lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
                    return this._tutorialStates.presentDocs;
                },
            ],
        });

        const skipToLinksButton: InfoButton = {
            title: 'Links Tutorial',
            toolTip: 'Skip',
            btnType: ButtonType.ClickButton,
            scripts: {
                onClick: 'this.skipToState(this.tutorialStates.multipleDocs)',
            },
            targetState: this._tutorialStates.multipleDocs,
        };

        const skipToPinsButton: InfoButton = {
            title: 'Pins Tutorial',
            toolTip: 'Skip',
            btnType: ButtonType.ClickButton,
            scripts: {
                onClick: 'this.skipToState(this.tutorialStates.makePresentation)',
            },
            targetState: this._tutorialStates.makePresentation,
        };

        // const skipToPresentationButton: Button = {
        //     title: "Collections Tutorial",
        //     toolTip: "Skip",
        //     btnType: ButtonType.ClickButton,
        //     scripts: {
        //         onClick: "this.skipToState(this.tutorialStates.nestedCollections)"
        //     },
        //     targetState: this.tutorialStates.nestedCollections
        // };

        const ending = InfoState("If you have any more questions, feel free to ask Dash's AI Bot!");

        // Traditional tutorial

        const completed = InfoState('Eager to learn more? Click the ? icon in the top right corner to read our full documentation.', { docRemoved: [() => this._props.childDocs().length === 1, () => this._tutorialStates.start] }, 'documentation.png');

        const penMode = InfoState("You're in pen mode! Click and drag to draw your first masterpiece, then click the Ink button once you're done.", {
            activePen: [() => Doc.ActiveTool !== InkTool.Ink, () => completed],
        });

        const briefArtisticFeature = InfoState("Finally, want to explore the art feature of Dash? Click the 'Ink' button on the hotbar then click the pen button.", {
            penModeActivated: [() => Doc.ActiveTool === InkTool.Ink, () => penMode],
        });

        const activatePresentation = InfoState('Lastly, click the linked node and start the presentation!', {
            presentation: [() => Doc.ActivePresentation?.presentation_status === 'auto', () => briefArtisticFeature],
        });

        const deletePresentation = InfoState(
            "Cool! Click 'setOnClick to follow primary link' for your non-presentation doc and try deleting the presentation.",
            {
                docRemoved: [
                    () => this._props.childDocs().length < docCounter,
                    () => {
                        docCounter -= 1;
                        return activatePresentation;
                    },
                ],
            },
            'onclick-node.gif'
        );

        const trailedPresentation = InfoState(
            'Try linking your presentation to the last doc you created (now highlighted).',
            {
                linkAdd: [
                    () => Doc.Links(lastDocCreated)?.length > linkCounter,
                    () => {
                        linkCounter += 1;
                        return deletePresentation;
                    },
                ],
                docAdded: [
                    () => this._props.childDocs().length > docCounter,
                    () => {
                        docCounter += 1;
                        // Last doc that is not the presentation
                        lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 2];
                        linkCounter = Doc.Links(lastDocCreated)?.length;
                        return deletePresentation;
                    },
                ],
            },
            'link-presentation.gif'
        );

        const pinnedPresentation = InfoState(
            'Want to see something cool? Zoom out, click the trail button on the presentation, and drag it inside the canvas.',
            {
                docAdded: [
                    () => this._props.childDocs().length > docCounter,
                    () => {
                        docCounter += 1;
                        // Last doc that is not the presentation
                        lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 2];
                        Doc.HighlightDoc(lastDocCreated);
                        linkCounter = Doc.Links(lastDocCreated)?.length;
                        return trailedPresentation;
                    },
                ],
            },
            'dash-trail-explanation.gif'
        );

        const pinnedDoc2 = InfoState('You pinned another doc. Press autoplay to the right to show your presentation!', {
            autoPresentation: [() => Doc.ActivePresentation?.presentation_status === 'auto', () => pinnedPresentation],
        });

        const pinnedDoc = InfoState('You just pinned your doc. Pin another doc to add to the presentation!', {
            addedDoc: [
                () => this._props.childDocs().length > docCounter,
                () => {
                    docCounter += 1;
                    lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
                    return pinnedDoc;
                },
            ],
            docPinned: [
                () => DocListCast(Doc.ActivePresentation?.data).length > presentationCounter,
                () => {
                    presentationCounter++;
                    return pinnedDoc2;
                },
            ],
        });

        const editLink = InfoState(
            "Want to make your link visible? Click 'show link'.",
            {
                docCreated: [
                    () => this._props.childDocs().length > docCounter,
                    () => {
                        docCounter += 1;
                        lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
                        return this._tutorialStates.makePresentation;
                    },
                ],
            },
            'show-link.gif'
        );

        const madeLink = InfoState(
            'You made your first link! You can view your links by selecting the blue dot.',
            {
                linkViewed: [
                    () => DocButtonState.Instance.LinkEditorDocView,
                    () => {
                        docCounter = this._props.childDocs().length;
                        return editLink;
                    },
                ],
            },
            'dash-following-link.gif'
        );

        const startedLink = InfoState(
            'Now click the highlighted link icon on your other document.',
            {
                linkAdd: [
                    () => Doc.Links(lastDocCreated)?.length > linkCounter,
                    () => {
                        linkCounter += 1;
                        return madeLink;
                    },
                ],
            },
            'dash-create-link-board.gif'
        );

        this._tutorialStates.movedDoc = InfoState(
            "Great moves! Try creating a second document.", 
            {
                docCreated: [
                    () => this._props.childDocs().length > docCounter, 
                    () => {
                        docCounter += 1
                        lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1]
                        return this._tutorialStates.multipleDocs
                    }
                ],
            },
            'dash-colon-menu.gif'); // prettier-ignore

        this._tutorialStates.start = InfoState(
            "Welcome to Dash! Click anywhere and begin typing ':' to create your first document.",
            {
                docCreated: [
                    () => this._props.childDocs().length > docCounter,
                    () => {
                        docCounter += 1;
                        lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
                        return this._tutorialStates.movedDoc;
                    },
                ],
            },
            undefined,
            [skipToLinksButton, skipToPinsButton]
        );

        // Information on created nested collections
        const createdMarquee = InfoState(
            'Next, right click and drag a square to create the collection',
            {
                marqueeMade: [
                    () => this._props.childDocs().length < docCounter,
                    () => {
                        docCounter -= 1;
                        return ending;
                    },
                ],
            },
            'dash-create-collection-marquee.gif'
        );

        const marqueeSelection = InfoState('Want an easier way to make a collection of docs? First add two docs you want to make a collection of', {
            marqueeMade: [
                () => this._props.childDocs().length > docCounter,
                () => {
                    docCounter += 1;
                    lastDocCreated = this._props.childDocs()[this.props.childDocs().length - 1];
                    return createdMarquee;
                },
            ],
        });

        // Explanation of importing

        const easierImport = InfoState('Or, for easier access, you can drag any of the accepted file types from your computer or a webpage and drop it into your dashboard. This includes images, videos, audio, pdfs, and more!', {}, 'dash-', [
            this.createNextButton(ending),
        ]);

        this._tutorialStates.importFile = InfoState('Want to learn how to import a file? Import using the import menu on the left hand side', {}, 'dash-import.gif', [this.createNextButton(easierImport)]);

        // Editing documents

        // Accessed by right-clicking anywhere on the target document or selecting the three bars menu at the bottom of the document chrome

        const extraContentsOfDoc = InfoState('Lastly, all documents also have a context-sensitive toolbar. The toolbar contents vary depending on the document type.', {}, 'context-toolbar.png', [this.createNextButton(ending)]);

        const contentsofDoc = InfoState('You can access the context of a doc through right-clicking anywhere on the target document or selecting the three bars menu at the bottom of the document chrome', {}, 'dash-context-menu.gif', [
            this.createNextButton(extraContentsOfDoc),
        ]);

        const propertiesofDoc = InfoState('You can also access the properties of a doc through the double arrows in the top right or the single arrow on the right edge of the screen', {}, 'dash-properties-pane.gif', [
            this.createNextButton(contentsofDoc),
        ]);

        this._tutorialStates.editingDocuments = InfoState('Want to learn how to edit a document? Either left or right click the document', {}, 'document-chrome.png', [this.createNextButton(propertiesofDoc)]);
        return this._tutorialStates.start;
    };

    render() {
        return !this.currState ? null : (
            <CollectionFreeFormInfoState
                next={this.skipToState} // This ensures skipToState is passed correctly
                close={this._props.close}
                infoState={this.currState}
            />
        );
    }
}