Skip to content

Commit

Permalink
Highlight active menu item
Browse files Browse the repository at this point in the history
  • Loading branch information
tschumpr committed Jul 24, 2024
1 parent f677a82 commit 2ad8390
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Geopilot.Frontend/src/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export const Header: FC<HeaderProps> = ({ clientSettings, hasDrawerToggle, handl
setUserMenuOpen(newOpen);
};

const isActive = (path: string) => {
if (path === "") {
return location.pathname === "/";
}
return location.pathname.split("/").includes(path);
};

return (
<>
<AppBar>
Expand Down Expand Up @@ -119,6 +126,7 @@ export const Header: FC<HeaderProps> = ({ clientSettings, hasDrawerToggle, handl
<List>
<ListItem key={t("delivery").toUpperCase()} disablePadding>
<ListItemButton
selected={isActive("")}
onClick={() => {
navigate("/");
}}>
Expand All @@ -128,6 +136,7 @@ export const Header: FC<HeaderProps> = ({ clientSettings, hasDrawerToggle, handl
<AdminTemplate>
<ListItem key={t("administration").toUpperCase()} disablePadding>
<ListItemButton
selected={isActive("admin")}
onClick={() => {
navigate("/admin");
}}>
Expand All @@ -136,6 +145,7 @@ export const Header: FC<HeaderProps> = ({ clientSettings, hasDrawerToggle, handl
</ListItem>
<ListItem key={t("stacBrowser").toUpperCase()} disablePadding>
<ListItemButton
selected={isActive("browser")}
onClick={() => {
window.open("/browser", "_blank");
}}>
Expand Down
9 changes: 9 additions & 0 deletions src/Geopilot.Frontend/src/pages/admin/Admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ export const Admin: FC<AdminProps> = ({ clientSettings }) => {
}
};

const isActive = (path: string) => {
if (path === "") {
return location.pathname === "/";
}
return location.pathname.split("/").includes(path);
};

const drawerWidth = "250px";
const drawerContent = (
<div>
Expand All @@ -45,6 +52,7 @@ export const Admin: FC<AdminProps> = ({ clientSettings }) => {
<List>
<ListItem key={"deliveryOverview"} disablePadding>
<ListItemButton
selected={isActive("delivery-overview")}
onClick={() => {
navigateTo("delivery-overview");
}}>
Expand All @@ -57,6 +65,7 @@ export const Admin: FC<AdminProps> = ({ clientSettings }) => {
{["users", "mandates", "organisations"].map(link => (
<ListItem key={link} disablePadding>
<ListItemButton
selected={isActive(link)}
onClick={() => {
navigateTo(link);
}}>
Expand Down

0 comments on commit 2ad8390

Please sign in to comment.