diff --git a/src/app/components/Sidebar/index.tsx b/src/app/components/Sidebar/index.tsx index 76e6577..ed3952a 100644 --- a/src/app/components/Sidebar/index.tsx +++ b/src/app/components/Sidebar/index.tsx @@ -7,6 +7,7 @@ import { } from "react-icons/bs"; import { ThemeSwitcher } from "../ThemeSwitcher/ThemeSwitcher"; import { SidebarItem } from "./item"; +import { useUserStore } from "@/app/stores/userStore"; export const Sidebar = ({ items, @@ -21,11 +22,12 @@ export const Sidebar = ({ const pathName = usePathname(); // State to manage menu openness - const [open, setOpen] = useState(true); + const { setSidebarIsOpen, sidebarIsOpen } = useUserStore(); const [isMobile, setIsMobile] = useState(false); useEffect(() => { const handleResize = () => { + if (sidebarIsOpen) return; if (window.innerWidth <= 1024 && !isMobile) { setIsMobile(true); } else if (window.innerWidth > 1024 && isMobile) { @@ -33,6 +35,8 @@ export const Sidebar = ({ } }; + console.log("sidebarIsOpen", sidebarIsOpen); + handleResize(); window.addEventListener("resize", handleResize); return () => window.removeEventListener("resize", handleResize); @@ -40,25 +44,25 @@ export const Sidebar = ({ useEffect(() => { if (isMobile) { - setOpen(false); + setSidebarIsOpen(false); } + // eslint-disable-next-line react-hooks/exhaustive-deps }, [isMobile]); return (