Updated the Header.jsx
This commit is contained in:
parent
d5558f0ddf
commit
1f41e899c7
@ -1,17 +1,36 @@
|
|||||||
import {AppBar, IconButton, Toolbar, Typography} from "@mui/material";
|
import {AppBar, IconButton, Toolbar, Typography} from "@mui/material";
|
||||||
import {Menu} from "@mui/icons-material";
|
import {Menu} from "@mui/icons-material";
|
||||||
|
import {useContext, useEffect} from "react";
|
||||||
|
import {projectSidebar, sidebar} from "@/common/routes/index.jsx";
|
||||||
|
import {useLocation} from "react-router-dom";
|
||||||
|
import {ProjectContext} from "@/states/Dashboard/contexts/Project";
|
||||||
|
|
||||||
const drawerWidth = 240;
|
const drawerWidth = 260;
|
||||||
|
|
||||||
|
export const Header = ({toggleOpen}) => {
|
||||||
|
const location = useLocation();
|
||||||
|
const {currentProject} = useContext(ProjectContext);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
document.title = "LicenseAPI - " + getTitleByPath();
|
||||||
|
}, [location]);
|
||||||
|
|
||||||
|
const getTitleByPath = () => {
|
||||||
|
const route = [...sidebar, ...projectSidebar].find((route) => location.pathname
|
||||||
|
.replace(currentProject?.id, ":projectId").startsWith(route.path) && route.path !== "/");
|
||||||
|
if (route) return route.name;
|
||||||
|
return "Startseite";
|
||||||
|
}
|
||||||
|
|
||||||
export const Header = () => {
|
|
||||||
return (
|
return (
|
||||||
<AppBar position="fixed" sx={{width: { sm: `calc(100% - ${drawerWidth}px)` }, ml: { sm: `${drawerWidth}px` }}}>
|
<AppBar position="fixed" sx={{width: { sm: `calc(100% - ${drawerWidth}px)` }, ml: { sm: `${drawerWidth}px` }}}
|
||||||
|
color="inherit">
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
<IconButton color="inherit" aria-label="open drawer" edge="start" onClick={() => {}}
|
<IconButton color="inherit" aria-label="open drawer" edge="start" onClick={toggleOpen}
|
||||||
sx={{ mr: 2, display: { sm: 'none' } }}>
|
sx={{ mr: 2, display: { sm: 'none' } }}>
|
||||||
<Menu />
|
<Menu />
|
||||||
</IconButton>
|
</IconButton>
|
||||||
<Typography variant="h6" noWrap>Home</Typography>
|
<Typography variant="h6" fontWeight={700}>{getTitleByPath()}</Typography>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user