-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.tsx
More file actions
76 lines (65 loc) · 2.22 KB
/
index.tsx
File metadata and controls
76 lines (65 loc) · 2.22 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
import { createRouter, RouterProvider } from '@tanstack/react-router';
import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import * as Fx from './src/fx/fx';
import * as AlbumRoute from './src/routes/album';
import * as ArtistRoute from './src/routes/artist';
import * as ArtistsRoute from './src/routes/artists';
import * as LayoutRoute from './src/routes/layoutRoute';
import * as LoginRoute from './src/routes/login';
import * as RootRoute from './src/routes/root';
import { StoreProvider } from './src/store/context';
import { createAppStore } from './src/store/store';
import { subscribeToStoreStateUpdates } from './src/storeFx/subscribeToStoreStateUpdates';
const container = document.createElement('div');
container.style.width = '100%';
container.style.height = '100%';
container.style.overflow = 'scroll';
container.style.position = 'absolute';
container.style.inset = '0';
container.style.zIndex = '-9999';
container.style.visibility = 'hidden';
document.body.appendChild(container);
new ResizeObserver(entries => {
const border = entries[0].borderBoxSize[0];
const content = entries[0].contentBoxSize[0];
document.documentElement.style.setProperty(
'--scrollbar-inline-size',
`${border.inlineSize - content.inlineSize}px`,
);
document.documentElement.style.setProperty(
'--scrollbar-block-size',
`${border.blockSize - content.blockSize}px`,
);
}).observe(container);
const store = createAppStore();
const router = createRouter({
context: { store },
defaultPreload: 'intent',
scrollRestoration: true,
routeTree: RootRoute.route.addChildren([
LoginRoute.route,
LayoutRoute.route.addChildren([
AlbumRoute.route,
ArtistRoute.route,
ArtistsRoute.route,
]),
]),
});
store.subscribe((state, prevState) => {
if (state.auth.credentials !== prevState.auth.credentials) {
router.invalidate();
}
});
Fx.runAsync(subscribeToStoreStateUpdates(), { store }).then(result => {
if (result.TAG !== 0) throw new Error();
});
const rootEl = document.querySelector('#app');
if (!rootEl) throw new Error();
createRoot(rootEl).render(
<StrictMode>
<StoreProvider store={store}>
<RouterProvider router={router} />
</StoreProvider>
</StrictMode>,
);