add back button

This commit is contained in:
proddy
2024-07-21 19:13:54 +02:00
parent 152b7bdee2
commit d0976cd660
4 changed files with 52 additions and 28 deletions

View File

@@ -1,5 +1,7 @@
import type { FC } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import MenuIcon from '@mui/icons-material/Menu';
import { AppBar, IconButton, Toolbar, Typography } from '@mui/material';
@@ -10,30 +12,52 @@ interface LayoutAppBarProps {
onToggleDrawer: () => void;
}
const LayoutAppBar: FC<LayoutAppBarProps> = ({ title, onToggleDrawer }) => (
<AppBar
position="fixed"
sx={{
width: { md: `calc(100% - ${DRAWER_WIDTH}px)` },
ml: { md: `${DRAWER_WIDTH}px` },
boxShadow: 'none',
backgroundColor: '#2e586a'
}}
>
<Toolbar>
<IconButton
color="inherit"
edge="start"
onClick={onToggleDrawer}
sx={{ mr: 2, display: { md: 'none' } }}
>
<MenuIcon />
</IconButton>
<Typography variant="h6" noWrap component="div">
{title}
</Typography>
</Toolbar>
</AppBar>
);
const LayoutAppBar: FC<LayoutAppBarProps> = ({ title, onToggleDrawer }) => {
const pathnames = useLocation()
.pathname.split('/')
.filter((x) => x);
const navigate = useNavigate();
let show_back = false;
if (pathnames.length > 1) {
show_back = pathnames[0] !== 'system' || pathnames[1] === 'espsystemstatus';
}
return (
<AppBar
position="fixed"
sx={{
width: { md: `calc(100% - ${DRAWER_WIDTH}px)` },
ml: { md: `${DRAWER_WIDTH}px` },
boxShadow: 'none',
backgroundColor: '#2e586a'
}}
>
<Toolbar>
<IconButton
color="inherit"
edge="start"
onClick={onToggleDrawer}
sx={{ mr: 2, display: { md: 'none' } }}
>
<MenuIcon />
</IconButton>
{show_back && (
<IconButton
color="inherit"
edge="start"
onClick={() => navigate(pathnames[0])}
>
<ArrowBackIcon />
</IconButton>
)}
<Typography variant="h6" noWrap component="div">
{title}
</Typography>
</Toolbar>
</AppBar>
);
};
export default LayoutAppBar;