Files
Checkmate/client/src/Components/v2/sidebar/index.tsx
T

78 lines
2.0 KiB
TypeScript
Raw Normal View History

2026-02-10 21:54:31 +00:00
import { useEffect } from "react";
2026-02-10 19:21:57 +00:00
import Stack from "@mui/material/Stack";
import List from "@mui/material/List";
import { useSidebar } from "@/Hooks/useSidebar.js";
import { Logo } from "@/Components/v2/sidebar/Logo";
import { getMenu } from "@/Components/v2/sidebar/Menu";
import { NavItem } from "@/Components/v2/sidebar/NavItem";
2026-02-10 21:54:31 +00:00
import { useNavigate, useLocation } from "react-router";
2026-02-10 19:21:57 +00:00
import { useTranslation } from "react-i18next";
import { useTheme, useMediaQuery } from "@mui/material";
import { useDispatch } from "react-redux";
2026-02-10 21:54:31 +00:00
import { setCollapsed } from "@/Features/UI/uiSlice";
2026-02-10 19:21:57 +00:00
export const Sidebar = () => {
const dispatch = useDispatch();
const navigate = useNavigate();
2026-02-10 21:54:31 +00:00
const location = useLocation();
2026-02-10 19:21:57 +00:00
const { t } = useTranslation();
const { width, transition } = useSidebar();
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
const menu = getMenu(t);
2026-02-10 21:54:31 +00:00
useEffect(() => {
dispatch(setCollapsed({ collapsed: isSmall }));
}, [isSmall, dispatch]);
2026-02-10 19:21:57 +00:00
return (
<Stack
component="aside"
2026-02-10 21:54:31 +00:00
position={isSmall ? "fixed" : "sticky"}
2026-02-10 19:21:57 +00:00
top={0}
left={0}
minHeight={"100vh"}
maxHeight={"100vh"}
paddingTop={theme.spacing(6)}
paddingBottom={theme.spacing(6)}
gap={theme.spacing(6)}
borderRight={`1px solid ${theme.palette.divider}`}
width={width}
sx={{
transition: transition,
zIndex: isSmall ? (t) => t.zIndex.drawer : "auto",
}}
>
<List
component="nav"
disablePadding
sx={{
px: theme.spacing(6),
height: "100%",
}}
>
2026-02-10 21:54:31 +00:00
<Logo
pt={theme.spacing(8)}
pb={theme.spacing(10)}
/>
2026-02-10 19:21:57 +00:00
{menu.map((item) => {
const selected = location.pathname.startsWith(`/${item.path}`);
return (
<NavItem
key={item.path}
item={item}
selected={selected}
onClick={() => {
navigate(`/${item.path}`);
if (isSmall) {
2026-02-10 21:54:31 +00:00
dispatch(setCollapsed({ collapsed: true }));
2026-02-10 19:21:57 +00:00
}
}}
/>
);
})}
</List>
</Stack>
);
};