-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.tsx
95 lines (86 loc) · 2.63 KB
/
index.tsx
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
import * as React from 'react';
import queryString from 'query-string';
import {Pages} from './Pages';
import {ErrorBoundary} from './components/ErrorBoundary';
import {MemoryRouter, Route} from 'react-router';
import {ExtraArg, init, useAppDispatch} from './action';
import {Provider} from 'react-redux';
import {reducer} from './reducer';
import {Parser} from './parser';
import {errorHandler} from './errorhandler';
import {Routes} from 'react-router-dom';
import {configureStore} from '@reduxjs/toolkit';
import {webDarkTheme, webLightTheme} from '@fluentui/react-theme';
import {FluentProvider} from '@fluentui/react-components';
import {createRoot} from 'react-dom/client';
import {useAppSelector} from './state';
const Import = React.lazy(
() => import(/* webpackChunkName: 'import', webpackPrefetch: true */'./components/Import'),
);
const Export = React.lazy(
() => import(/* webpackChunkName: 'export', webpackPrefetch: true */'./components/Export'),
);
const About = React.lazy(
() => import(/* webpackChunkName: 'about' */'./components/About'),
);
const LicenseInformation = React.lazy(
() => import(/* webpackChunkName: 'license' */'./components/LicenseInformation'),
);
const extraArg: ExtraArg = {parser: new Parser()};
const store = configureStore({
reducer,
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
thunk: {
extraArgument: extraArg,
},
}).concat(errorHandler),
});
function Initializer({children}): React.ReactElement {
useAppDispatch()(init());
return children;
}
function Theme({children}: React.PropsWithChildren) {
const initialized = useAppSelector(state => state.initialized);
const isDarkMode = initialized && Office.context && Office.context.officeTheme && Office.context.officeTheme.isDarkTheme;
return (
<FluentProvider theme={isDarkMode ? webDarkTheme : webLightTheme}>
{children}
</FluentProvider>
);
}
function App(): React.ReactElement {
return (
<ErrorBoundary>
<React.Suspense fallback=''>
<Provider store={store}>
<Theme>
<Initializer>
<MemoryRouter>
<Routes>
<Route path='/' element={<ParamRouter />} />
</Routes>
</MemoryRouter>
</Initializer>
</Theme>
</Provider>
</React.Suspense>
</ErrorBoundary>
);
}
function ParamRouter() {
const page = queryString.parse(location.search).page as string;
switch (page) {
case Pages.import:
return <Import />;
case Pages.export:
return <Export />;
case Pages.about:
return <About />;
case Pages.licenseInformation:
return <LicenseInformation />;
default:
throw new Error(`unknown page: ${page}`);
}
}
createRoot(document.getElementById('root')).render(<App />);