generated from Luis/nextjs-python-web-template
dynamic-routing-sidebar #67
@@ -9,6 +9,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
useMediaQuery,
|
useMediaQuery,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { useGetAllEntities } from "@/api/entities/entities";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import React, { ReactNode } from "react";
|
import React, { ReactNode } from "react";
|
||||||
|
|
||||||
@@ -33,32 +34,7 @@ type MenuEntry = {
|
|||||||
subMenuEntries?: MenuEntry[];
|
subMenuEntries?: MenuEntry[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const menuEntityEntries: MenuEntry[] = [
|
export let menuEntityEntries: MenuEntry[] = [];
|
||||||
{
|
|
||||||
icon: <PersonIcon />,
|
|
||||||
label: "C1",
|
|
||||||
to: "/client/C1",
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <PersonIcon />,
|
|
||||||
label: "C2",
|
|
||||||
to: "/client/C2",
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <PersonIcon />,
|
|
||||||
label: "C3",
|
|
||||||
to: "/client/C3",
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
icon: <PersonIcon />,
|
|
||||||
label: "C4",
|
|
||||||
to: "/client/C4",
|
|
||||||
disabled: false,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
export const menuEntries: MenuEntry[] = [
|
export const menuEntries: MenuEntry[] = [
|
||||||
{
|
{
|
||||||
@@ -96,6 +72,7 @@ interface SidebarProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function Sidebar(props: SidebarProps) {
|
export function Sidebar(props: SidebarProps) {
|
||||||
|
const { data: entityData } = useGetAllEntities();
|
||||||
const { show, onClose } = props;
|
const { show, onClose } = props;
|
||||||
const [activeMenuItem, setActiveMenuItem] = React.useState(
|
const [activeMenuItem, setActiveMenuItem] = React.useState(
|
||||||
typeof window !== "undefined" ? window.location.pathname : "",
|
typeof window !== "undefined" ? window.location.pathname : "",
|
||||||
@@ -113,12 +90,22 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
|
if (entityData) {
|
||||||
|
menuEntityEntries = Array.isArray(entityData.data)
|
||||||
|
? entityData.data.map((entity) => ({
|
||||||
|
icon: <PersonIcon />,
|
||||||
|
label: entity.name,
|
||||||
|
to: `/client/${entity.name}`,
|
||||||
|
disabled: false,
|
||||||
|
}))
|
||||||
|
: [];
|
||||||
|
}
|
||||||
if (isSmallerScreen) {
|
if (isSmallerScreen) {
|
||||||
setCollapseMenuOpen(false);
|
setCollapseMenuOpen(false);
|
||||||
} else {
|
} else {
|
||||||
setCollapseMenuOpen(true);
|
setCollapseMenuOpen(true);
|
||||||
}
|
}
|
||||||
}, [isSmallerScreen]);
|
}, [isSmallerScreen, entityData]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside
|
<aside
|
||||||
@@ -213,7 +200,7 @@ export function Sidebar(props: SidebarProps) {
|
|||||||
unmountOnExit
|
unmountOnExit
|
||||||
>
|
>
|
||||||
<List component="div" disablePadding>
|
<List component="div" disablePadding>
|
||||||
{menuEntityEntries.map((menuEntry, idx) => (
|
{menuEntityEntries?.map((menuEntry, idx) => (
|
||||||
<ListItemButton
|
<ListItemButton
|
||||||
key={idx}
|
key={idx}
|
||||||
sx={{ pl: 4 }}
|
sx={{ pl: 4 }}
|
||||||
|
|||||||
Reference in New Issue
Block a user