-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
83 lines (76 loc) · 3.02 KB
/
App.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
// SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
// SPDX-License-Identifier: Apache-2.0
import React, {Suspense, useEffect} from 'react';
import {Provider} from 'react-redux';
import './App.scss';
import TopBar from './components/TopBar';
import Sidebar from './components/Sidebar';
import MainContent from './components/MainContent';
import {Persistor, Store} from './store';
import Box from '@mui/material/Box';
import {ThemeProvider} from '@mui/material/styles';
import Theme from './util/Theme';
import {PersistGate} from 'redux-persist/integration/react';
import {useAppDispatch, useAppSelector} from './store/hooks';
import {selectDistrict} from './store/DataSelectionSlice';
import {I18nextProvider, useTranslation} from 'react-i18next';
import i18n from './util/i18n';
import {MUILocalization} from './components/shared/MUILocalization';
import LoadingOverlay from 'components/shared/LoadingOverlay';
/**
* This is the root element of the React application. It divides the main screen area into the three main components.
* The top bar, the sidebar and the main content area.
*/
export default function App(): JSX.Element {
return (
<Suspense
// Use Loading Overlay with default background and primary color (theme isn't loaded at this point)
fallback={<LoadingOverlay show={true} overlayColor={'#F0F0F2'} throbberColor={'#543CF0'}></LoadingOverlay>}
>
<Provider store={Store}>
<ThemeProvider theme={Theme}>
<PersistGate loading={null} persistor={Persistor}>
<I18nextProvider i18n={i18n}>
<MUILocalization>
<Initializer />
<Box id='app' display='flex' flexDirection='column' sx={{height: '100%', width: '100%'}}>
<TopBar />
<Box
id='app-content'
sx={{
display: 'flex',
flexDirection: 'row',
flexGrow: 1,
alignItems: 'stretch',
width: '100%',
}}
>
<Sidebar />
<MainContent />
</Box>
</Box>
</MUILocalization>
</I18nextProvider>
</PersistGate>
</ThemeProvider>
</Provider>
</Suspense>
);
}
/**
* This component serves to initialize state, that is required for the whole application and has no other responsible
* component.
*/
function Initializer() {
const {t} = useTranslation();
const selectedDistrict = useAppSelector((state) => state.dataSelection.district);
const dispatch = useAppDispatch();
// This effect ensures, that we get the correct translation for 'germany'. This is required, as the store initializes
// before the translations are available.
useEffect(() => {
if (selectedDistrict.ags === '00000' && selectedDistrict.name === '') {
dispatch(selectDistrict({ags: '00000', name: t('germany'), type: ''}));
}
}, [selectedDistrict, t, dispatch]);
return null;
}