import React, { useState, useEffect } from "react"; import { Drawer, IconButton, List } from "@material-ui/core"; import { Home as HomeIcon, NotificationsNone as NotificationsIcon, People as ProfilesIcon, AttachMoney as LightningIcon, QuestionAnswer as SupportIcon, LibraryBooks as LibraryIcon, HelpOutline as FAQIcon, ArrowBack as ArrowBackIcon, } from "@material-ui/icons"; import { useTheme } from "@material-ui/styles"; import { withRouter } from "react-router-dom"; import classNames from "classnames"; // styles import useStyles from "./styles"; // components import SidebarLink from "./components/SidebarLink/SidebarLink"; import Dot from "./components/Dot"; // context import { useLayoutState, useLayoutDispatch, toggleSidebar, } from "../../context/LayoutContext"; const structure = [ { id: 0, label: "Timeline", link: "/app/timeline", icon: }, { id: 1, label: "Profiles", link: "/app/profiles", icon: }, { id: 2, label: "Lightning", link: "/app/lightning", icon: }, ]; function Sidebar({ location }) { var classes = useStyles(); var theme = useTheme(); // global var { isSidebarOpened } = useLayoutState(); var layoutDispatch = useLayoutDispatch(); // local var [isPermanent, setPermanent] = useState(true); useEffect(function() { window.addEventListener("resize", handleWindowWidthChange); handleWindowWidthChange(); return function cleanup() { window.removeEventListener("resize", handleWindowWidthChange); }; }); return (
toggleSidebar(layoutDispatch)}>
{structure.map(link => ( ))} ); // ################################################################## function handleWindowWidthChange() { var windowWidth = window.innerWidth; var breakpointWidth = theme.breakpoints.values.md; var isSmallScreen = windowWidth < breakpointWidth; if (isSmallScreen && isPermanent) { setPermanent(false); } else if (!isSmallScreen && !isPermanent) { setPermanent(true); } } } export default withRouter(Sidebar);