aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/Main.tsx
blob: b6dfed687a4c403a7bd565dd69e435a01deed30e (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
/* eslint-disable no-new */
// if ((module as any).hot) {
//     (module as any).hot.accept();
// }

import * as dotenv from 'dotenv'; // see https://github.com/motdotla/dotenv#how-do-i-use-dotenv-with-import
import * as React from 'react';
import * as ReactDOM from 'react-dom/client';
import { AssignAllExtensions } from '../../extensions/Extensions';
import { FieldLoader } from '../../fields/FieldLoader';
import { BranchingTrailManager } from '../util/BranchingTrailManager';
import { CurrentUserUtils } from '../util/CurrentUserUtils';
import { PingManager } from '../util/PingManager';
import { ReplayMovements } from '../util/ReplayMovements';
import { TrackMovements } from '../util/TrackMovements';
import { KeyManager } from './GlobalKeyHandler';
import { MainView } from './MainView';
import { CollectionView } from './collections/CollectionView';
import { CollectionFreeFormInfoUI } from './collections/collectionFreeForm/CollectionFreeFormInfoUI';
import './global/globalScripts';
import { LinkFollower } from '../util/LinkFollower';

dotenv.config();

AssignAllExtensions();
FieldLoader.ServerLoadStatus = { requested: 0, retrieved: 0, message: 'cache' }; // bcz: not sure why this is needed to get the code loaded properly...

(async () => {
    MainView.Live = window.location.search.includes('live');
    const rootEle = document.getElementById('root');
    if (!rootEle) return;
    rootEle.style.zIndex = '0';
    const root = ReactDOM.createRoot(rootEle);
    root.render(<FieldLoader />);
    window.location.search.includes('safe') && CollectionView.SetSafeMode(true);
    const info = await CurrentUserUtils.loadCurrentUser();
    // if (info.email === 'guest') DocServer.Control.makeReadOnly();
    if (!info.userDocumentId) {
        alert('Fatal Error: user not found in database');
        return;
    }
    await CurrentUserUtils.loadUserDocument(info);
    setTimeout(() => {
        document.getElementById('root')!.addEventListener(
            'wheel',
            event => {
                if (event.ctrlKey) {
                    event.preventDefault();
                }
            },
            true
        );
        const startload = (document as any).startLoad;
        const loading = Date.now() - (startload ? Number(startload) : Date.now() - 3000);
        console.log('Loading Time = ' + loading);
        const d = new Date();
        d.setTime(d.getTime() + 100 * 24 * 60 * 60 * 1000);
        const expires = 'expires=' + d.toUTCString();
        document.cookie = `loadtime=${loading};${expires};path=/`;
        new TrackMovements();
        new ReplayMovements();
        new BranchingTrailManager({});
        new PingManager();
        new KeyManager();

        // iniitialize plugin apis
        CollectionFreeFormInfoUI.Init();
        LinkFollower.Init();
        root.render(<MainView />);
    }, 0);
})();