diff --git a/components/layout/Sidebar.tsx b/components/layout/Sidebar.tsx index 07a4369..3d76c5f 100644 --- a/components/layout/Sidebar.tsx +++ b/components/layout/Sidebar.tsx @@ -5,7 +5,7 @@ import UserMenu from "@/components/layout/UserMenu"; import Link from "next/link"; import { usePathname } from "next/navigation"; import React, { useEffect, useState } from "react"; -import { useWindowSize } from "usehooks-ts"; +import { useMediaQuery } from "usehooks-ts"; import Logo from "../icons/Logo"; import SidebarSection from "@/components/layout/SidebarSection"; import clsx from "clsx"; @@ -94,96 +94,93 @@ function Sidebar({ children }: React.PropsWithChildren) { const pathname = usePathname(); const currentItem = items.find((v) => pathname.startsWith(v.path)); const selection = currentItem?.title; - const { width, height } = useWindowSize(); - const [isMobile, setMobile] = useState(false); + const isMobile = !useMediaQuery( + "(min-width: 1024px) and (min-height: 600px)", + ); const [isOpened, setOpened] = useState(false); useEffect(() => { - if (width >= 1024 && height >= 600) { - setMobile(false); + if (!isMobile) { setOpened(true); } else { - setMobile(true); setOpened(false); } - }, [width, height]); + }, [isMobile]); return ( - {isMobile && isOpened ? ( -
setOpened(false)} - /> - ) : ( - <> - )} - +
setOpened(false)} + /> + {children} );