diff --git a/next/src/layout/sidebar.tsx b/next/src/layout/sidebar.tsx index 3edc8c27ab..92fe7bb018 100644 --- a/next/src/layout/sidebar.tsx +++ b/next/src/layout/sidebar.tsx @@ -1,5 +1,5 @@ import type { FC, PropsWithChildren, ReactNode } from "react"; -import { Fragment, useState } from "react"; +import { Fragment, useEffect, useState } from "react"; import { Transition } from "@headlessui/react"; import { useAuth } from "../hooks/useAuth"; import type { Session } from "next-auth"; @@ -59,7 +59,7 @@ const LinkItem = (props: { const SidebarLayout = (props: Props) => { const router = useRouter(); const { session, signIn, signOut, status } = useAuth(); - const [sidebarOpen, setSidebarOpen] = useState(true); + const [sidebarOpen, setSidebarOpen] = useState(false); const [t] = useTranslation("drawer"); const [showSettings, setShowSettings] = useState(false); @@ -69,6 +69,20 @@ const SidebarLayout = (props: Props) => { }); const userAgents = query.data ?? []; + useEffect(() => { + const handleResize = () => { + const isDesktop = window.innerWidth >= 1280 + setSidebarOpen(isDesktop); + }; + handleResize(); // Initial check on open + window.addEventListener('resize', handleResize); + + return () => { + window.removeEventListener('resize', handleResize); + }; + }, []); + + return (
@@ -192,7 +206,7 @@ const SidebarLayout = (props: Props) => {
- +
{props.children}