import React, { useCallback, useEffect, useState } from 'react'; import AppBar from '@mui/material/AppBar'; import Box from '@mui/material/Box'; import { ThemeProvider } from '@mui/material/styles'; import { useLocation } from 'react-router-dom'; import AppHeader from 'components/AppHeader'; import Backdrop from 'components/Backdrop'; import { useApi } from 'hooks/useApi'; import { useLocalStorage } from 'hooks/useLocalStorage'; import AppToolbar from './components/AppToolbar'; import AppDrawer, { DRAWER_WIDTH, isDrawerPath } from './components/drawers/AppDrawer'; import ElevationScroll from './components/ElevationScroll'; import { ExperimentalAppRoutes } from './routes/AppRoutes'; import theme from './theme'; import './AppOverrides.scss'; interface ExperimentalAppSettings { isDrawerPinned: boolean } const DEFAULT_EXPERIMENTAL_APP_SETTINGS: ExperimentalAppSettings = { isDrawerPinned: false }; const ExperimentalApp = () => { const [ appSettings, setAppSettings ] = useLocalStorage('ExperimentalAppSettings', DEFAULT_EXPERIMENTAL_APP_SETTINGS); const [ isDrawerActive, setIsDrawerActive ] = useState(appSettings.isDrawerPinned); const { user } = useApi(); const location = useLocation(); 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 (
{/* * TODO: These components are not used, but views interact with them directly so the need to be * present in the dom. We add them in a hidden element to prevent errors. */}
muiTheme.zIndex.drawer + 1 }} >
); }; export default ExperimentalApp;