1
0
Fork 0
mirror of https://github.com/jellyfin/jellyfin-web synced 2025-03-30 19:56:21 +00:00
jellyfin-web/src/apps/dashboard/AppLayout.tsx

109 lines
3.6 KiB
TypeScript
Raw Normal View History

2023-09-25 02:13:16 -04:00
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import { useTheme } from '@mui/material/styles';
2023-09-25 13:54:33 -04:00
import React, { FC, useCallback, useEffect, useState } from 'react';
2023-09-25 02:13:16 -04:00
import { Outlet, useLocation } from 'react-router-dom';
2023-09-20 00:02:26 -04:00
import AppBody from 'components/AppBody';
2023-09-25 13:54:33 -04:00
import AppToolbar from 'components/toolbar/AppToolbar';
2023-09-25 02:13:16 -04:00
import ElevationScroll from 'components/ElevationScroll';
import { DRAWER_WIDTH } from 'components/ResponsiveDrawer';
import { useApi } from 'hooks/useApi';
import { useLocalStorage } from 'hooks/useLocalStorage';
2023-09-25 02:13:16 -04:00
import AppDrawer from './components/drawer/AppDrawer';
2023-09-25 13:54:33 -04:00
import './AppOverrides.scss';
interface AppLayoutProps {
drawerlessPaths: string[]
}
2023-09-25 02:13:16 -04:00
interface DashboardAppSettings {
isDrawerPinned: boolean
}
const DEFAULT_APP_SETTINGS: DashboardAppSettings = {
isDrawerPinned: false
};
2023-09-20 00:02:26 -04:00
2023-09-25 13:54:33 -04:00
const AppLayout: FC<AppLayoutProps> = ({
drawerlessPaths
}) => {
2023-09-25 02:13:16 -04:00
const [ appSettings, setAppSettings ] = useLocalStorage<DashboardAppSettings>('DashboardAppSettings', DEFAULT_APP_SETTINGS);
const [ isDrawerActive, setIsDrawerActive ] = useState(appSettings.isDrawerPinned);
const location = useLocation();
const theme = useTheme();
const { user } = useApi();
2023-09-25 13:54:33 -04:00
const isDrawerAvailable = !drawerlessPaths.some(path => location.pathname.startsWith(`/${path}`));
2023-09-25 02:13:16 -04:00
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 ]);
2023-09-20 00:02:26 -04:00
return (
2023-09-25 02:13:16 -04:00
<Box sx={{ display: 'flex' }}>
<ElevationScroll elevate={isDrawerOpen}>
<AppBar
position='fixed'
sx={{ zIndex: (muiTheme) => muiTheme.zIndex.drawer + 1 }}
>
<AppToolbar
isDrawerAvailable={isDrawerAvailable}
isDrawerOpen={isDrawerOpen}
onDrawerButtonClick={onToggleDrawer}
/>
</AppBar>
</ElevationScroll>
<AppDrawer
open={isDrawerOpen}
onClose={onToggleDrawer}
onOpen={onToggleDrawer}
/>
<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 && {
transition: theme.transitions.create('margin', {
easing: theme.transitions.easing.easeOut,
duration: theme.transitions.duration.enteringScreen
}),
marginLeft: 0
})
}}
>
<AppBody>
<Outlet />
</AppBody>
</Box>
</Box>
2023-09-20 00:02:26 -04:00
);
};
export default AppLayout;