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

91 lines
2.9 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';
2023-11-28 10:26:14 -05:00
import { type Theme } from '@mui/material/styles';
import useMediaQuery from '@mui/material/useMediaQuery';
import React, { FC, useCallback, 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 AppTabs from './components/AppTabs';
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
2023-09-25 13:54:33 -04:00
const AppLayout: FC<AppLayoutProps> = ({
drawerlessPaths
}) => {
2023-11-28 10:26:14 -05:00
const [ isDrawerActive, setIsDrawerActive ] = useState(false);
2023-09-25 02:13:16 -04:00
const location = useLocation();
const { user } = useApi();
2024-01-07 02:48:29 -05:00
const isMediumScreen = useMediaQuery((t: Theme) => t.breakpoints.up('md'));
const isDrawerAvailable = Boolean(user)
2023-11-28 10:26:14 -05:00
&& !drawerlessPaths.some(path => location.pathname.startsWith(`/${path}`));
const isDrawerOpen = isDrawerActive && isDrawerAvailable;
2023-09-25 02:13:16 -04:00
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' }}>
2023-11-28 10:26:14 -05:00
<ElevationScroll elevate={false}>
2023-09-25 02:13:16 -04:00
<AppBar
position='fixed'
2023-11-28 10:26:14 -05:00
sx={{
width: {
xs: '100%',
2024-01-07 02:48:29 -05:00
md: isDrawerAvailable ? `calc(100% - ${DRAWER_WIDTH}px)` : '100%'
2023-11-28 10:26:14 -05:00
},
ml: {
xs: 0,
2024-01-07 02:48:29 -05:00
md: isDrawerAvailable ? DRAWER_WIDTH : 0
2023-11-28 10:26:14 -05:00
}
}}
2023-09-25 02:13:16 -04:00
>
<AppToolbar
2024-01-07 02:48:29 -05:00
isDrawerAvailable={!isMediumScreen && isDrawerAvailable}
2023-09-25 02:13:16 -04:00
isDrawerOpen={isDrawerOpen}
onDrawerButtonClick={onToggleDrawer}
>
<AppTabs isDrawerOpen={isDrawerOpen} />
</AppToolbar>
2023-09-25 02:13:16 -04:00
</AppBar>
</ElevationScroll>
{
isDrawerAvailable && (
<AppDrawer
open={isDrawerOpen}
onClose={onToggleDrawer}
onOpen={onToggleDrawer}
/>
)
}
2023-09-25 02:13:16 -04:00
<Box
component='main'
sx={{
width: '100%',
2023-11-28 10:26:14 -05:00
flexGrow: 1
2023-09-25 02:13:16 -04:00
}}
>
<AppBody>
<Outlet />
</AppBody>
</Box>
</Box>
2023-09-20 00:02:26 -04:00
);
};
export default AppLayout;