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, Menu, X } from "lucide-react"; import { useState, useEffect } from "react"; import api from "../lib/api"; 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); window.addEventListener("scroll", onScroll); return () => window.removeEventListener("scroll", onScroll); }, []); useEffect(() => { 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 (
StreamHoard . {version && v{version}} {user && ( )}
{user ? (
{user.is_admin && ( )}
{active && (
{active.name}
{active.name?.[0]?.toUpperCase() || "U"}
)}
) : ( Sign in )}
{user && mobileOpen && ( )}
); }; export default Navbar;