From 3be45bd8342d535fc0605b36d9cb5cb55c048373 Mon Sep 17 00:00:00 2001 From: arsam Date: Fri, 18 Sep 2026 23:17:40 +0330 Subject: [PATCH] Import source: vault/components/header Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality. --- vault/components/header.tsx | 161 ++++++++++++++++++++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 vault/components/header.tsx diff --git a/vault/components/header.tsx b/vault/components/header.tsx new file mode 100644 index 0000000..fe24b3c --- /dev/null +++ b/vault/components/header.tsx @@ -0,0 +1,161 @@ +"use client"; + +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { motion } from "framer-motion"; +import { useTheme } from "next-themes"; +import { useState, useEffect } from "react"; +import { Lock, Sun, Moon, Menu, X, LogOut } from "lucide-react"; +import { Button } from "@/components/ui/button"; +import { cn } from "@/lib/utils"; +import { api } from "@/lib/api-client"; +import { User } from "@/lib/types"; + +const NAV_LINKS = [ + { href: "/", label: "Home" }, + { href: "/snippets", label: "Snippets" }, + { href: "/snippets/new", label: "New" }, +]; + +export function Header() { + const pathname = usePathname(); + const { theme, setTheme } = useTheme(); + const [mounted, setMounted] = useState(false); + const [mobileOpen, setMobileOpen] = useState(false); + const [user, setUser] = useState(null); + + useEffect(() => { + // eslint-disable-next-line react-hooks/set-state-in-effect + setMounted(true); + api.me().then(({ user }) => setUser(user)).catch(() => setUser(null)); + }, [pathname]); + + const handleLogout = async () => { + await api.logout(); + setUser(null); + window.location.href = "/login"; + }; + + if (pathname.startsWith("/s/")) return null; + + return ( + +
+ +
+ +
+ + CVault + + + + + +
+ {mounted && ( + + )} + + {user ? ( + + ) : ( + + + + )} + + +
+
+ + {mobileOpen && ( + +
+ {NAV_LINKS.map((link) => ( + setMobileOpen(false)}> + + + ))} + {user ? ( + + ) : ( + setMobileOpen(false)}> + + + )} +
+
+ )} +
+ ); +}