2023-06-01 12:12:16 -04:00
|
|
|
import React, { useCallback, useEffect, useState } from 'react';
|
|
|
|
import AppBar from '@mui/material/AppBar';
|
|
|
|
import Box from '@mui/material/Box';
|
2023-09-27 02:07:40 -04:00
|
|
|
import { useTheme } from '@mui/material/styles';
|
2023-06-01 12:12:16 -04:00
|
|
|
import { Outlet, useLocation } from 'react-router-dom';
|
|
|
|
|
2023-09-27 02:07:40 -04:00
|
|
|
import AppBody from 'components/AppBody';
|
|
|
|
import ElevationScroll from 'components/ElevationScroll';
|
|
|
|
import { DRAWER_WIDTH } from 'components/ResponsiveDrawer';
|
2023-06-01 12:12:16 -04:00
|
|
|
import { useApi } from 'hooks/useApi';
|
|
|
|
import { useLocalStorage } from 'hooks/useLocalStorage';
|
|
|
|
|
|
|
|
import AppToolbar from './components/AppToolbar';
|
2023-09-27 02:07:40 -04:00
|
|
|
import AppDrawer, { isDrawerPath } from './components/drawers/AppDrawer';
|
2023-06-01 12:12:16 -04:00
|
|
|
|
|
|
|
import './AppOverrides.scss';
|
|
|
|
|
|
|
|
interface ExperimentalAppSettings {
|
|
|
|
isDrawerPinned: boolean
|
|
|
|
}
|
|
|
|
|
|
|
|
const DEFAULT_EXPERIMENTAL_APP_SETTINGS: ExperimentalAppSettings = {
|
|
|
|
isDrawerPinned: false
|
|
|
|
};
|
|
|
|
|
|
|
|
const AppLayout = () => {
|
|
|
|
const [ appSettings, setAppSettings ] = useLocalStorage<ExperimentalAppSettings>('ExperimentalAppSettings', DEFAULT_EXPERIMENTAL_APP_SETTINGS);
|
|
|
|
const [ isDrawerActive, setIsDrawerActive ] = useState(appSettings.isDrawerPinned);
|
|
|
|
const { user } = useApi();
|
|
|
|
const location = useLocation();
|
2023-09-27 02:07:40 -04:00
|
|
|
const theme = useTheme();
|
2023-06-01 12:12:16 -04:00
|
|
|
|
|
|
|
const isDrawerAvailable = isDrawerPath(location.pathname);
|
|
|
|
const isDrawerOpen = isDrawerActive && isDrawerAvailable && Boolean(user);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (isDrawerActive !== appSettings.isDrawerPinned) {
|
|
|
|
setAppSettings({
|
|
|
|
...appSettings,
|
|
|
|
isDrawerPinned: isDrawerActive
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}, [ appSettings, isDrawerActive, setAppSettings ]);
|
|
|
|
|
|
|
|
const onToggleDrawer = useCallback(() => {
|
|
|
|
setIsDrawerActive(!isDrawerActive);
|
|
|
|
}, [ isDrawerActive, setIsDrawerActive ]);
|
|
|
|
|
|
|
|
return (
|
2023-09-27 02:07:40 -04:00
|
|
|
<Box sx={{ display: 'flex' }}>
|
|
|
|
<ElevationScroll elevate={isDrawerOpen}>
|
|
|
|
<AppBar
|
|
|
|
position='fixed'
|
|
|
|
sx={{ zIndex: (muiTheme) => muiTheme.zIndex.drawer + 1 }}
|
|
|
|
>
|
|
|
|
<AppToolbar
|
|
|
|
isDrawerOpen={isDrawerOpen}
|
|
|
|
onDrawerButtonClick={onToggleDrawer}
|
|
|
|
/>
|
|
|
|
</AppBar>
|
|
|
|
</ElevationScroll>
|
2023-06-01 12:12:16 -04:00
|
|
|
|
2023-09-27 02:07:40 -04:00
|
|
|
<AppDrawer
|
|
|
|
open={isDrawerOpen}
|
|
|
|
onClose={onToggleDrawer}
|
|
|
|
onOpen={onToggleDrawer}
|
|
|
|
/>
|
2023-06-01 12:12:16 -04:00
|
|
|
|
2023-09-27 02:07:40 -04:00
|
|
|
<Box
|
|
|
|
component='main'
|
|
|
|
sx={{
|
|
|
|
width: '100%',
|
|
|
|
flexGrow: 1,
|
|
|
|
transition: theme.transitions.create('margin', {
|
|
|
|
easing: theme.transitions.easing.sharp,
|
|
|
|
duration: theme.transitions.duration.leavingScreen
|
|
|
|
}),
|
|
|
|
marginLeft: 0,
|
|
|
|
...(isDrawerAvailable && {
|
|
|
|
marginLeft: {
|
|
|
|
sm: `-${DRAWER_WIDTH}px`
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
...(isDrawerActive && {
|
2023-06-01 12:12:16 -04:00
|
|
|
transition: theme.transitions.create('margin', {
|
2023-09-27 02:07:40 -04:00
|
|
|
easing: theme.transitions.easing.easeOut,
|
|
|
|
duration: theme.transitions.duration.enteringScreen
|
2023-06-01 12:12:16 -04:00
|
|
|
}),
|
2023-09-27 02:07:40 -04:00
|
|
|
marginLeft: 0
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<AppBody>
|
|
|
|
<Outlet />
|
|
|
|
</AppBody>
|
2023-06-01 12:12:16 -04:00
|
|
|
</Box>
|
2023-09-27 02:07:40 -04:00
|
|
|
</Box>
|
2023-06-01 12:12:16 -04:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AppLayout;
|