-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathRoot.tsx
More file actions
45 lines (38 loc) · 1.63 KB
/
Root.tsx
File metadata and controls
45 lines (38 loc) · 1.63 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
import {Box, CircularProgress, CssBaseline, Stack, ThemeProvider} from "@mui/material";
import {Outlet, useLocation} from "react-router-dom";
import {FC, lazy, useContext} from "react";
import useTelegramBackButton from "./hooks/telegram/useTelegramBackButton.ts";
import useTelegramTheme from "./hooks/telegram/useTelegramTheme.ts";
import {EncryptionManagerContext} from "./managers/encryption.tsx";
import {StorageManagerContext} from "./managers/storage/storage.tsx";
import Decrypt from "./pages/Decrypt.tsx";
const PasswordSetup = lazy(() => import("./pages/PasswordSetup.tsx"));
export function LoadingIndicator() {
return <Stack sx={{width: '100vw', height: '100vh', position: 'fixed'}}
justifyContent="center"
alignItems="center">
<CircularProgress/>
</Stack>;
}
const Root: FC = () => {
useTelegramBackButton();
const theme = useTelegramTheme();
const encryptionManager = useContext(EncryptionManagerContext);
const storageManager = useContext(StorageManagerContext);
const { pathname } = useLocation();
return (
<>
<ThemeProvider theme={theme}>
<CssBaseline />
<Box sx={{padding: 1.5}}>
{!encryptionManager?.storageChecked ? <LoadingIndicator/> :
(!encryptionManager.passwordCreated ? <PasswordSetup/> :
(encryptionManager.isLocked ? (pathname === "/reset" ? <Outlet/> : <Decrypt/>) :
(storageManager?.ready ? <Outlet/> :
<LoadingIndicator/>)))}
</Box>
</ThemeProvider>
</>
)
}
export default Root