import { mdiBug, mdiForum, mdiKeyVariant, mdiLinkLock } from "@mdi/js"; import Icon from "@mdi/react"; import Box from "@mui/material/Box"; import Drawer from "@mui/material/Drawer"; import List from "@mui/material/List"; import Toolbar from "@mui/material/Toolbar"; import { useTheme } from "@mui/material/styles"; import type {} from "@mui/material/themeCssVarsAugmentation"; import useMediaQuery from "@mui/material/useMediaQuery"; import * as React from "react"; import { useUserInfo } from "./BaseAuthenticatedPage"; import DashboardSidebarContext from "./DashboardSidebarContext"; import DashboardSidebarDividerItem from "./DashboardSidebarDividerItem"; import DashboardSidebarPageItem from "./DashboardSidebarPageItem"; import { DRAWER_WIDTH, MINI_DRAWER_WIDTH } from "./constants"; import { getDrawerSxTransitionMixin, getDrawerWidthTransitionMixin, } from "./mixins"; export interface DashboardSidebarProps { expanded?: boolean; setExpanded: (expanded: boolean) => void; disableCollapsibleSidebar?: boolean; container?: Element; } export default function DashboardSidebar({ expanded = true, setExpanded, disableCollapsibleSidebar = false, container, }: DashboardSidebarProps) { const theme = useTheme(); const user = useUserInfo(); const isOverSmViewport = useMediaQuery(theme.breakpoints.up("sm")); const isOverMdViewport = useMediaQuery(theme.breakpoints.up("md")); const [isFullyExpanded, setIsFullyExpanded] = React.useState(expanded); React.useEffect(() => { if (expanded) { const drawerWidthTransitionTimeout = setTimeout(() => { setIsFullyExpanded(true); }, theme.transitions.duration.enteringScreen); return () => clearTimeout(drawerWidthTransitionTimeout); } setIsFullyExpanded(false); return () => {}; }, [expanded, theme.transitions.duration.enteringScreen]); const mini = !disableCollapsibleSidebar && !expanded; const handleSetSidebarExpanded = React.useCallback( (newExpanded: boolean) => () => { setExpanded(newExpanded); }, [setExpanded] ); const handlePageItemClick = React.useCallback(() => { if (!isOverSmViewport) { setExpanded(false); } }, [mini, setExpanded, isOverSmViewport]); const hasDrawerTransitions = isOverSmViewport && (!disableCollapsibleSidebar || isOverMdViewport); const getDrawerContent = React.useCallback( (viewport: "phone" | "tablet" | "desktop") => ( } href="/" /> } href="/matrix_link" /> } href="/tokens" /> } href="/wsdebug" /> ), [ mini, hasDrawerTransitions, isFullyExpanded, user.info.matrix_account_connected, ] ); const getDrawerSharedSx = React.useCallback( (isTemporary: boolean) => { const drawerWidth = mini ? MINI_DRAWER_WIDTH : DRAWER_WIDTH; return { displayPrint: "none", width: drawerWidth, flexShrink: 0, ...getDrawerWidthTransitionMixin(expanded), ...(isTemporary ? { position: "absolute" } : {}), [`& .MuiDrawer-paper`]: { position: "absolute", width: drawerWidth, boxSizing: "border-box", backgroundImage: "none", ...getDrawerWidthTransitionMixin(expanded), }, }; }, [expanded, mini] ); const sidebarContextValue = React.useMemo(() => { return { onPageItemClick: handlePageItemClick, mini, fullyExpanded: isFullyExpanded, hasDrawerTransitions, }; }, [handlePageItemClick, mini, isFullyExpanded, hasDrawerTransitions]); return ( {getDrawerContent("phone")} {getDrawerContent("tablet")} {getDrawerContent("desktop")} ); }