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

132 lines
3.4 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";
2026-02-10 22:17:13 +00:00
import Divider from "@mui/material/Divider";
2026-02-10 19:21:57 +00:00
import { useSidebar } from "@/Hooks/useSidebar.js";
import { Logo } from "@/Components/v2/sidebar/Logo";
2026-02-10 22:47:39 +00:00
import { getMenu, getBottomMenu, getAccountMenu } from "@/Components/v2/sidebar/Menu";
2026-02-10 19:21:57 +00:00
import { NavItem } from "@/Components/v2/sidebar/NavItem";
2026-02-10 22:24:35 +00:00
import { StarPrompt } from "@/Components/v2/sidebar/StarPrompt";
2026-02-10 19:21:57 +00:00
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
2026-02-10 22:17:13 +00:00
const URL_MAP: Record<string, string> = {
support: "https://discord.com/invite/NAb6H3UTjK",
discussions: "https://github.com/bluewave-labs/checkmate/discussions",
docs: "https://bluewavelabs.gitbook.io/checkmate",
changelog: "https://github.com/bluewave-labs/checkmate/releases",
};
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 22:17:13 +00:00
const bottomMenu = getBottomMenu(t);
2026-02-10 22:47:39 +00:00
const accountMenu = getAccountMenu(t);
2026-02-10 19:21:57 +00:00
2026-02-10 21:54:31 +00:00
useEffect(() => {
dispatch(setCollapsed({ collapsed: isSmall }));
}, [isSmall, dispatch]);
2026-02-10 22:17:13 +00:00
const handleNavClick = (path: string) => {
const url = URL_MAP[path];
if (url) {
window.open(url, "_blank", "noreferrer");
} else {
navigate(`/${path}`);
}
if (isSmall) {
dispatch(setCollapsed({ collapsed: true }));
}
};
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),
2026-02-10 22:17:13 +00:00
flex: 1,
2026-02-10 19:21:57 +00:00
}}
>
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}
2026-02-10 22:17:13 +00:00
onClick={() => handleNavClick(item.path)}
/>
);
})}
</List>
2026-02-10 22:24:35 +00:00
<StarPrompt />
2026-02-10 22:17:13 +00:00
<List
component="nav"
disablePadding
sx={{ px: theme.spacing(6) }}
>
{bottomMenu.map((item) => {
const selected = location.pathname.startsWith(`/${item.path}`);
return (
<NavItem
key={item.path}
item={item}
selected={selected}
onClick={() => handleNavClick(item.path)}
2026-02-10 19:21:57 +00:00
/>
);
})}
</List>
2026-02-10 22:17:13 +00:00
<Divider sx={{ borderColor: theme.palette.divider }} />
2026-02-10 22:47:39 +00:00
<List
component="nav"
disablePadding
sx={{ px: theme.spacing(6) }}
>
{accountMenu.map((item) => {
const selected = location.pathname.startsWith(`/${item.path}`);
return (
<NavItem
key={item.path}
item={item}
selected={selected}
onClick={() => handleNavClick(item.path)}
/>
);
})}
</List>
2026-02-10 19:21:57 +00:00
</Stack>
);
};