-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
97 lines (83 loc) · 2.57 KB
/
App.js
File metadata and controls
97 lines (83 loc) · 2.57 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
86
87
88
89
90
91
92
93
94
95
96
97
import React, { Suspense, lazy, useCallback, useEffect, useState } from 'react';
import { getBootExperience } from './app-mode';
import XPBootScreen from './XPBootScreen';
/* WinXP is imported eagerly so it mounts and fetches commissions
while the boot screen is still visible. */
import WinXP from 'WinXP';
const DrawingsAdminPage = lazy(() => import('./admin/DrawingsAdminPage'));
const MobileSite = lazy(() => import('./mobile-site/index'));
/* Pre-fetch commission full-size images into the browser cache
so popups open instantly after the preloader dismisses. */
function prefetchCommissionImages() {
fetch('/api/commissions/public', { cache: 'no-store' })
.then(r => r.json())
.then(data => {
(data.commissions || []).forEach(c => {
const urls = [c.imageUrl];
if (Array.isArray(c.imageVariants)) {
urls.push(...c.imageVariants);
}
urls.forEach(url => {
if (!url) return;
const img = new Image();
img.src = url;
});
});
})
.catch(() => {});
}
const App = () => {
const isAdminRoute = window.location.pathname.startsWith('/admin/drawings');
const isLayoutRoute = window.location.pathname.startsWith('/layout');
const [bootExperience] = useState(() =>
getBootExperience(window.location, window.innerWidth),
);
const [booting, setBooting] = useState(true);
const handleBootComplete = useCallback(() => setBooting(false), []);
useEffect(() => {
prefetchCommissionImages();
}, []);
useEffect(() => {
if (isAdminRoute) {
document.title = 'thinko admin';
return;
}
if (isLayoutRoute) {
document.title = 'thinko layout';
return;
}
document.title = 'thinko';
}, [isAdminRoute, isLayoutRoute]);
if (isAdminRoute) {
return (
<Suspense fallback={<XPBootScreen />}>
<DrawingsAdminPage />
</Suspense>
);
}
if (bootExperience === 'mobile') {
return (
<Suspense fallback={<XPBootScreen />}>
<MobileSite />
</Suspense>
);
}
/* Render desktop immediately behind the boot screen overlay so
images and API data load during the preloader animation.
visibility:hidden prevents the flash while keeping layout
intact so images can still load. */
return (
<>
{booting && <XPBootScreen onComplete={handleBootComplete} />}
<div
style={{
visibility: booting ? 'hidden' : 'visible',
minHeight: '100dvh',
}}
>
<WinXP enableLayoutDebug={isLayoutRoute} />
</div>
</>
);
};
export default App;