import { useEffect, useState } from "react"; import { Form, Link, useLocation } from "react-router"; import { useTranslation } from "react-i18next"; import { Avatar } from "./Avatar"; interface Props { user: { username: string; displayName: string | null }; } // Mobile drawer for the navbar. Replaces the "everything in a row" // desktop layout with a hamburger trigger and a slide-out panel that // holds all the same destinations. Bell + the dropdown's account // section move inside; the bell badge still surfaces on the trigger // itself via the parent navbar. export function MobileNavMenu({ user }: Props) { const { t } = useTranslation("journal"); const [open, setOpen] = useState(false); const location = useLocation(); // Close the drawer on navigation. React Router pushes a new location // when a Link is followed; this effect picks that up. useEffect(() => { setOpen(false); }, [location.pathname]); // Close on Escape; lock body scroll while open. useEffect(() => { if (!open) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") setOpen(false); }; document.addEventListener("keydown", onKey); const prevOverflow = document.body.style.overflow; document.body.style.overflow = "hidden"; return () => { document.removeEventListener("keydown", onKey); document.body.style.overflow = prevOverflow; }; }, [open]); const linkClass = (path: string) => { const active = location.pathname === path || location.pathname.startsWith(path + "/"); return `block rounded-md px-3 py-2 text-base font-medium ${ active ? "bg-blue-50 text-blue-700" : "text-gray-700 hover:bg-gray-50" }`; }; return ( <> {open && (
{/* Backdrop */}
)} ); }