diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index 9934ff6..a53b014 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -1,7 +1,7 @@ -import { Link, NavLink, useNavigate } from "react-router-dom"; +import { Link, NavLink, useNavigate, useLocation } from "react-router-dom"; import { useAuth } from "../lib/auth"; import { useProfile } from "../lib/profile"; -import { Search, LogOut, Upload, Settings as SettingsIcon } from "lucide-react"; +import { Search, LogOut, Upload, Settings as SettingsIcon, Menu, X } from "lucide-react"; import { useState, useEffect } from "react"; import api from "../lib/api"; @@ -9,8 +9,10 @@ export const Navbar = () => { const { user, logout } = useAuth(); const { active } = useProfile(); const nav = useNavigate(); + const location = useLocation(); const [scrolled, setScrolled] = useState(false); const [version, setVersion] = useState(""); + const [mobileOpen, setMobileOpen] = useState(false); useEffect(() => { const onScroll = () => setScrolled(window.scrollY > 20); @@ -22,11 +24,17 @@ export const Navbar = () => { api.get("/version").then(({ data }) => setVersion(data.version)).catch(() => {}); }, []); + // Close the mobile menu on navigation so it never lingers open over the next page. + useEffect(() => { setMobileOpen(false); }, [location.pathname]); + const linkClass = ({ isActive }) => `text-sm tracking-wide transition-colors duration-300 ${isActive ? "text-white" : "text-[#8A8A8A] hover:text-white"}`; + const mobileLinkClass = ({ isActive }) => + `block py-3 text-base tracking-wide transition-colors duration-300 ${isActive ? "text-white" : "text-[#8A8A8A]"}`; + return ( -
+
@@ -68,15 +76,44 @@ export const Navbar = () => {
)} - + ) : ( Sign in )} + + {user && mobileOpen && ( + + )}
); };