|
1 | 1 | import { Route } from "react-router-dom";
|
2 |
| -import classes from './app.module.scss'; |
3 |
| -import {MemoryRouter as Router} from "react-router-dom"; |
| 2 | +import classes from "./app.module.scss"; |
| 3 | +import { MemoryRouter as Router } from "react-router-dom"; |
4 | 4 | import { ThemeProvider, createTheme } from "@mui/material";
|
5 |
| -import { Content, MainMenu } from './components'; |
6 |
| -import { Files, Links, Texts } from './pages'; |
| 5 | +import { Content, MainMenu } from "./components"; |
| 6 | +import { Files, Links, Texts } from "./pages"; |
| 7 | +import AppContext from "./app_context"; |
| 8 | +import { useEffect, useState } from "react"; |
| 9 | +import { App as ShortApp } from "./common/data.types"; |
| 10 | +import { appRepository } from "./repositories"; |
| 11 | +import { config } from "./core"; |
7 | 12 |
|
8 | 13 | const theme = createTheme({
|
9 |
| - spacing: 16, |
| 14 | + spacing: 16, |
10 | 15 | });
|
11 | 16 |
|
12 | 17 | function App() {
|
13 |
| - return <Router basename={process.env.PUBLIC_URL}> |
14 |
| - <ThemeProvider theme={theme}> |
15 |
| - <div className={classes.root}> |
16 |
| - <MainMenu /> |
17 |
| - <Content> |
18 |
| - <Route path="/" element={<Links />} /> |
19 |
| - <Route path="/texts" element={<Texts />} /> |
20 |
| - <Route path="/files" element={<Files />} /> |
21 |
| - </Content> |
22 |
| - </div> |
23 |
| - </ThemeProvider> |
24 |
| - </Router>; |
| 18 | + const [isLoading, setIsLoading] = useState(true); |
| 19 | + const [appContextValue, setAppContextValue] = useState<ShortApp>(); |
| 20 | + useEffect(() => { |
| 21 | + (async() => { |
| 22 | + const app = await appRepository.get() |
| 23 | + setAppContextValue(app); |
| 24 | + config.domain = app.domain; |
| 25 | + setIsLoading(false); |
| 26 | + })(); |
| 27 | + }, []); |
| 28 | + |
| 29 | + return ( |
| 30 | + <Router basename={process.env.PUBLIC_URL}> |
| 31 | + <ThemeProvider theme={theme}> |
| 32 | + <AppContext.Provider value={appContextValue}> |
| 33 | + <div className={classes.root}> |
| 34 | + {!isLoading ? <><MainMenu /> |
| 35 | + <Content> |
| 36 | + <Route path="/" element={<Links />} /> |
| 37 | + <Route path="/texts" element={<Texts />} /> |
| 38 | + <Route path="/files" element={<Files />} /> |
| 39 | + </Content> |
| 40 | + </> : null} |
| 41 | + </div> |
| 42 | + </AppContext.Provider> |
| 43 | + </ThemeProvider> |
| 44 | + </Router> |
| 45 | + ); |
25 | 46 | }
|
26 | 47 |
|
27 | 48 | export default App;
|
0 commit comments