Updated the Header.jsx

This commit is contained in:
Mathias Wagner 2023-08-01 22:34:02 +02:00
parent d5558f0ddf
commit 1f41e899c7
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -1,17 +1,36 @@
import {AppBar, IconButton, Toolbar, Typography} from "@mui/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 (
<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>
<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' } }}>
<Menu />
</IconButton>
<Typography variant="h6" noWrap>Home</Typography>
<Typography variant="h6" fontWeight={700}>{getTitleByPath()}</Typography>
</Toolbar>
</AppBar>
)