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

153 lines
4.2 KiB
TypeScript
Raw Normal View History

2026-02-10 21:54:31 +00:00
import { useEffect } from "react";
2026-02-11 18:34:55 +00:00
import Backdrop from "@mui/material/Backdrop";
2026-02-10 19:21:57 +00:00
import Stack from "@mui/material/Stack";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
2026-02-10 19:21:57 +00:00
import List from "@mui/material/List";
2026-02-10 22:17:13 +00:00
import Divider from "@mui/material/Divider";
2026-02-28 21:48:42 +00:00
import { LAYOUT } from "@/Utils/Theme/constants";
import { typographyLevels } from "@/Utils/Theme/Palette";
2026-02-10 19:21:57 +00:00
import { useSidebar } from "@/Hooks/useSidebar.js";
2026-02-20 18:13:39 +00:00
import { Logo } from "@/Components/sidebar/Logo";
import { getMenu, getAccountMenu } from "@/Components/sidebar/Menu";
2026-02-20 18:13:39 +00:00
import { NavItem } from "@/Components/sidebar/NavItem";
import { StarPrompt } from "@/Components/sidebar/StarPrompt";
import { AuthFooter } from "@/Components/sidebar/Authfooter";
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://checkmate.so/docs",
2026-02-10 22:17:13 +00:00
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();
2026-08-31 09:56:59 -07:00
const { width, transition, transitionTiming, collapsed } = useSidebar();
2026-02-10 19:21:57 +00:00
const theme = useTheme();
const isSmall = useMediaQuery(theme.breakpoints.down("md"));
const menu = getMenu(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 (
2026-02-11 18:34:55 +00:00
<>
<Backdrop
open={!collapsed && isSmall}
onClick={() => dispatch(setCollapsed({ collapsed: true }))}
sx={{ zIndex: 999 }}
/>
<Stack
component="aside"
position={isSmall ? "fixed" : "sticky"}
top={0}
left={0}
minHeight={"100vh"}
maxHeight={"100vh"}
2026-02-28 21:48:42 +00:00
paddingTop={theme.spacing(LAYOUT.SM)}
paddingBottom={theme.spacing(LAYOUT.SM)}
gap={theme.spacing(LAYOUT.SM)}
2026-02-11 18:34:55 +00:00
borderRight={`1px solid ${theme.palette.divider}`}
width={width}
bgcolor={theme.palette.background.paper}
2026-02-10 19:21:57 +00:00
sx={{
2026-02-11 18:34:55 +00:00
touchAction: "none",
transition: transition,
zIndex: 1000,
2026-02-10 19:21:57 +00:00
}}
>
2026-02-11 18:34:55 +00:00
<List
component="nav"
disablePadding
sx={{
2026-02-28 21:48:42 +00:00
px: theme.spacing(LAYOUT.SM),
2026-02-11 18:34:55 +00:00
flex: 1,
}}
>
<Logo
2026-02-28 21:48:42 +00:00
pt={theme.spacing(LAYOUT.MD)}
pb={theme.spacing(LAYOUT.MD)}
2026-02-11 18:34:55 +00:00
/>
2026-08-31 09:59:26 -07:00
{menu.map((group) => (
<Box key={group.group}>
2026-08-31 09:56:59 -07:00
<Box
position="relative"
overflow="hidden"
>
<Typography
variant="eyebrow"
component="div"
color={theme.palette.text.disabled}
fontSize={typographyLevels.s}
paddingLeft={theme.spacing(5)}
paddingTop={theme.spacing(LAYOUT.SM)}
paddingBottom={theme.spacing(LAYOUT.XXS)}
2026-08-31 09:56:59 -07:00
whiteSpace="nowrap"
sx={{
opacity: collapsed ? 0 : 1,
transition: `opacity ${transitionTiming}`,
}}
>
{group.group}
</Typography>
2026-08-31 09:59:26 -07:00
<Divider
sx={{
position: "absolute",
top: "50%",
left: 0,
right: 0,
opacity: collapsed ? 1 : 0,
transition: `opacity ${transitionTiming}`,
}}
/>
2026-08-31 09:56:59 -07:00
</Box>
{group.items.map((item) => {
const selected = location.pathname.startsWith(`/${item.path}`);
return (
<NavItem
key={item.path}
item={item}
selected={selected}
onClick={() => handleNavClick(item.path)}
/>
);
})}
</Box>
))}
2026-02-11 18:34:55 +00:00
</List>
<StarPrompt />
2026-08-19 12:02:45 -07:00
2026-02-11 18:34:55 +00:00
<Divider sx={{ borderColor: theme.palette.divider }} />
2026-02-10 22:54:23 +00:00
2026-02-11 18:34:55 +00:00
<AuthFooter
collapsed={collapsed}
accountMenuItems={accountMenu}
/>
</Stack>
</>
2026-02-10 19:21:57 +00:00
);
};