|
1 | 1 | // import useStateWithStorage from '@eplant/util/useStateWithStorage' |
2 | | -import { Route, Routes } from 'react-router-dom' |
3 | 2 |
|
4 | | -import { CssBaseline, ThemeProvider } from '@mui/material' |
| 3 | +import { useEffect } from 'react' |
| 4 | + |
| 5 | +import { Box, CircularProgress, CssBaseline, useTheme } from '@mui/material' |
| 6 | +import { ThemeProvider } from '@mui/material/styles' |
5 | 7 |
|
6 | 8 | import { dark, light } from './css/theme' |
7 | | -import Sidebar from './UI/Sidebar' |
| 9 | +import { URLStateProvider } from './state/URLStateProvider' |
| 10 | +import { ViewContainer } from './UI/Layout/ViewContainer' |
| 11 | +import Sidebar, { collapsedSidebarWidth, sidebarWidth } from './UI/Sidebar' |
8 | 12 | import { useConfig } from './config' |
9 | | -import EplantLayout from './EplantLayout' |
10 | | -import { useDarkMode } from './state' |
| 13 | +import { |
| 14 | + useActiveGeneId, |
| 15 | + useActiveViewId, |
| 16 | + useDarkMode, |
| 17 | + useGeneticElements, |
| 18 | + usePageLoad, |
| 19 | + useSidebarState, |
| 20 | +} from './state' |
| 21 | +import { updateColors } from './updateColors' |
11 | 22 | export type EplantProps = Record<string, never> |
12 | | -export default function Eplant() { |
13 | | - const { rootPath } = useConfig() |
14 | | - const [darkMode] = useDarkMode() |
15 | 23 |
|
16 | | - return ( |
17 | | - <ThemeProvider theme={darkMode ? dark : light}> |
18 | | - <CssBaseline /> |
19 | | - <Routes> |
20 | | - <Route path={rootPath}> |
21 | | - <Route index element={<MainEplant />} /> |
22 | | - </Route> |
23 | | - </Routes> |
24 | | - </ThemeProvider> |
25 | | - ) |
26 | | -} |
27 | 24 | /** |
28 | 25 | * The main Eplant component. This is the root of the application. It contains the left nav and the layout. |
29 | 26 | * @returns {JSX.Element} The rendered Eplant component |
30 | 27 | */ |
| 28 | +const Eplant = () => { |
| 29 | + const [darkMode] = useDarkMode() |
| 30 | + const [isCollapse, setIsCollapse] = useSidebarState() |
| 31 | + const [activeGeneId, setActiveGeneId] = useActiveGeneId() |
| 32 | + const [activeViewId, setActiveViewId] = useActiveViewId() |
| 33 | + const theme = useTheme() |
| 34 | + const [globalProgress, loaded] = usePageLoad() |
| 35 | + const config = useConfig() |
| 36 | + useEffect(() => { |
| 37 | + if (loaded) { |
| 38 | + updateColors(theme) |
| 39 | + } |
| 40 | + }, [theme, loaded]) |
31 | 41 |
|
32 | | -// SideBar and EplantLayout children |
33 | | -export function MainEplant() { |
34 | 42 | return ( |
35 | | - <> |
| 43 | + <ThemeProvider theme={darkMode ? dark : light}> |
| 44 | + <CssBaseline /> |
36 | 45 | <Sidebar /> |
37 | | - <EplantLayout /> |
38 | | - </> |
| 46 | + <URLStateProvider> |
| 47 | + <Box |
| 48 | + sx={(theme) => ({ |
| 49 | + height: `calc(100% - ${theme.spacing(1)})`, |
| 50 | + left: `${isCollapse ? collapsedSidebarWidth : sidebarWidth}px`, |
| 51 | + right: '0px', |
| 52 | + position: 'absolute', |
| 53 | + marginTop: '0.5rem', |
| 54 | + boxSizing: 'border-box', |
| 55 | + transition: 'left 1s ease-out', |
| 56 | + backgroundColor: theme.palette.background.paper, |
| 57 | + })} |
| 58 | + > |
| 59 | + <Box |
| 60 | + sx={{ |
| 61 | + width: '100%', |
| 62 | + height: '100%', |
| 63 | + display: 'flex', |
| 64 | + alignItems: 'stretch', |
| 65 | + justifyContent: 'stretch', |
| 66 | + }} |
| 67 | + > |
| 68 | + <div /> |
| 69 | + {loaded ? ( |
| 70 | + <ViewContainer |
| 71 | + sx={{ |
| 72 | + width: '100%', |
| 73 | + height: '100%', |
| 74 | + }} |
| 75 | + ></ViewContainer> |
| 76 | + ) : ( |
| 77 | + <div> |
| 78 | + <CircularProgress |
| 79 | + variant='indeterminate' |
| 80 | + value={globalProgress * 100} |
| 81 | + /> |
| 82 | + </div> |
| 83 | + )} |
| 84 | + </Box> |
| 85 | + </Box> |
| 86 | + </URLStateProvider> |
| 87 | + </ThemeProvider> |
39 | 88 | ) |
40 | 89 | } |
| 90 | +export default Eplant |
0 commit comments