-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
85 lines (74 loc) · 2.24 KB
/
Copy pathApp.tsx
File metadata and controls
85 lines (74 loc) · 2.24 KB
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
import { ActionBar } from '@/components/ActionBar';
import { PropertiesBar } from '@/components/PropertiesBar';
import { DefaultFallback, LoadingHero, ToastArea } from '@/components/feedback';
import { ElementInfoPanel, GraphWorkspace } from '@/components/graph';
import {
useAnimationShortcuts,
useClipboardShortcuts,
useGraphShortcuts,
useShareLink,
} from '@/hooks';
import {
AlgorithmsModal,
EdgeLabelModal,
HelpModal,
ImportExportModal,
NodeLabelModal,
SettingsModal,
} from '@/lazy';
import { isDev } from '@/utils/general';
import { Suspense, useEffect, useState } from 'react';
import { useSettings } from './contexts';
export function App() {
const [loadingApp, setLoadingApp] = useState(true);
useShareLink();
const {
ui: { disableElementsInfoPanel, theme },
} = useSettings();
useEffect(() => {
document.documentElement.dataset.theme = theme;
}, [theme]);
useEffect(() => {
// Simulated loading time - Users thinks its more natural
// https://uxmag.com/articles/let-your-users-wait
// https://www.reddit.com/r/webdev/comments/ul3tij/does_anyone_add_artificial_loading_time_to_their/
const timer = setTimeout(
() => {
setLoadingApp(false);
},
isDev() ? 0 : 700 + Math.random() * 300 // 700-1000ms
);
return () => {
clearTimeout(timer);
};
}, []);
if (loadingApp) {
return <LoadingHero />;
}
return (
<>
<GraphShortcutsBinding />
<PropertiesBar>
<ActionBar>
<GraphWorkspace />
{!disableElementsInfoPanel && <ElementInfoPanel />}
</ActionBar>
</PropertiesBar>
<Suspense fallback={<DefaultFallback />}>
<AlgorithmsModal />
<ImportExportModal />
<SettingsModal />
<HelpModal />
<NodeLabelModal />
<EdgeLabelModal />
</Suspense>
<ToastArea />
</>
);
}
function GraphShortcutsBinding() {
useGraphShortcuts();
useClipboardShortcuts();
useAnimationShortcuts();
return null;
}