2023-09-27 02:07:40 -04:00
|
|
|
import ArrowBack from '@mui/icons-material/ArrowBack';
|
|
|
|
import MenuIcon from '@mui/icons-material/Menu';
|
|
|
|
import Box from '@mui/material/Box';
|
|
|
|
import IconButton from '@mui/material/IconButton';
|
|
|
|
import Toolbar from '@mui/material/Toolbar';
|
|
|
|
import Tooltip from '@mui/material/Tooltip';
|
|
|
|
import Typography from '@mui/material/Typography';
|
|
|
|
import React, { FC, ReactNode } from 'react';
|
2023-10-06 17:49:26 -07:00
|
|
|
import { Link, useLocation } from 'react-router-dom';
|
2023-09-27 02:07:40 -04:00
|
|
|
|
|
|
|
import appIcon from 'assets/img/icon-transparent.png';
|
|
|
|
import { appRouter } from 'components/router/appRouter';
|
|
|
|
import { useApi } from 'hooks/useApi';
|
|
|
|
import globalize from 'scripts/globalize';
|
|
|
|
|
|
|
|
import UserMenuButton from './UserMenuButton';
|
|
|
|
|
|
|
|
interface AppToolbarProps {
|
|
|
|
buttons?: ReactNode
|
|
|
|
isDrawerAvailable: boolean
|
|
|
|
isDrawerOpen: boolean
|
|
|
|
onDrawerButtonClick: (event: React.MouseEvent<HTMLElement>) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
const onBackButtonClick = () => {
|
|
|
|
appRouter.back()
|
|
|
|
.catch(err => {
|
|
|
|
console.error('[AppToolbar] error calling appRouter.back', err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const AppToolbar: FC<AppToolbarProps> = ({
|
|
|
|
buttons,
|
|
|
|
children,
|
|
|
|
isDrawerAvailable,
|
|
|
|
isDrawerOpen,
|
|
|
|
onDrawerButtonClick
|
|
|
|
}) => {
|
|
|
|
const { user } = useApi();
|
|
|
|
const isUserLoggedIn = Boolean(user);
|
2023-10-06 17:49:26 -07:00
|
|
|
const currentLocation = useLocation();
|
2023-09-27 02:07:40 -04:00
|
|
|
|
|
|
|
const isBackButtonAvailable = appRouter.canGoBack();
|
|
|
|
|
2023-10-06 17:49:26 -07:00
|
|
|
// Handles a specific case to hide the user menu on the select server page while authenticated
|
2023-10-19 23:53:31 -04:00
|
|
|
const isUserMenuAvailable = currentLocation.pathname !== '/selectserver.html';
|
2023-10-06 17:49:26 -07:00
|
|
|
|
2023-09-27 02:07:40 -04:00
|
|
|
return (
|
|
|
|
<Toolbar
|
|
|
|
variant='dense'
|
|
|
|
sx={{
|
|
|
|
flexWrap: {
|
|
|
|
xs: 'wrap',
|
|
|
|
lg: 'nowrap'
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{isUserLoggedIn && isDrawerAvailable && (
|
|
|
|
<Tooltip title={globalize.translate(isDrawerOpen ? 'MenuClose' : 'MenuOpen')}>
|
|
|
|
<IconButton
|
|
|
|
size='large'
|
|
|
|
edge='start'
|
|
|
|
color='inherit'
|
|
|
|
aria-label={globalize.translate(isDrawerOpen ? 'MenuClose' : 'MenuOpen')}
|
|
|
|
onClick={onDrawerButtonClick}
|
|
|
|
>
|
|
|
|
<MenuIcon />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
|
|
|
|
{isBackButtonAvailable && (
|
|
|
|
<Tooltip title={globalize.translate('ButtonBack')}>
|
|
|
|
<IconButton
|
|
|
|
size='large'
|
|
|
|
// Set the edge if the drawer button is not shown
|
|
|
|
edge={!(isUserLoggedIn && isDrawerAvailable) ? 'start' : undefined}
|
|
|
|
color='inherit'
|
|
|
|
aria-label={globalize.translate('ButtonBack')}
|
|
|
|
onClick={onBackButtonClick}
|
|
|
|
>
|
|
|
|
<ArrowBack />
|
|
|
|
</IconButton>
|
|
|
|
</Tooltip>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<Box
|
|
|
|
component={Link}
|
|
|
|
to='/'
|
|
|
|
color='inherit'
|
|
|
|
aria-label={globalize.translate('Home')}
|
|
|
|
sx={{
|
|
|
|
ml: 2,
|
|
|
|
display: 'inline-flex',
|
|
|
|
textDecoration: 'none'
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<Box
|
|
|
|
component='img'
|
|
|
|
src={appIcon}
|
|
|
|
sx={{
|
|
|
|
height: '2rem',
|
|
|
|
marginInlineEnd: 1
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<Typography
|
|
|
|
variant='h6'
|
|
|
|
noWrap
|
|
|
|
component='div'
|
|
|
|
sx={{ display: { xs: 'none', sm: 'inline-block' } }}
|
|
|
|
>
|
|
|
|
Jellyfin
|
|
|
|
</Typography>
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
{children}
|
|
|
|
|
2023-10-06 17:49:26 -07:00
|
|
|
{isUserLoggedIn && isUserMenuAvailable && (
|
2023-09-27 02:07:40 -04:00
|
|
|
<>
|
|
|
|
<Box sx={{ display: 'flex', flexGrow: 1, justifyContent: 'flex-end' }}>
|
|
|
|
{buttons}
|
|
|
|
</Box>
|
|
|
|
|
|
|
|
<Box sx={{ flexGrow: 0 }}>
|
|
|
|
<UserMenuButton />
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</Toolbar>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default AppToolbar;
|