import { Link, useNavigate } from "@tanstack/react-router"; import { useState } from "react"; import { signOut } from "~/fns/auth"; import { useAction } from "~/hooks/use-action"; import { useUnreadNotifications, useViewer } from "~/hooks/use-viewer"; import { Avatar } from "./ui/Primitives"; import { buttonClass } from "./ui/Button"; import { inputClass } from "./ui/Field"; import { cn } from "~/utils/cn"; import { useDismiss } from "~/hooks/use-dismiss"; const NAV = [ { to: "/explore", label: "Explore" }, { to: "/search", label: "Search" }, ] as const; function UserMenu({ name }: { name: string }) { const navigate = useNavigate(); const [open, setOpen] = useState(false); const menuRef = useDismiss(open, () => setOpen(false)); const logout = useAction(signOut); const items = [ { to: "/$owner", params: { owner: name }, label: "Your profile" }, { to: "/settings", params: {}, label: "Settings" }, { to: "/settings/tokens", params: {}, label: "Access tokens" }, { to: "/settings/containers", params: {}, label: "Containers" }, { to: "/orgs/new", params: {}, label: "New organization" }, ] as const; async function handleSignOut() { await logout.run({}); await navigate({ to: "/" }); } return (
{open && (
Signed in as {name}
{items.map((item) => ( setOpen(false)} className="block px-3 py-2 text-sm text-gray-300 hover:bg-gray-900 hover:text-white" > {item.label} ))}
)}
); } export function SiteHeader() { const viewer = useViewer(); const unread = useUnreadNotifications(); const navigate = useNavigate(); return (
s gitfor
{ event.preventDefault(); const q = new FormData(event.currentTarget).get("q"); navigate({ to: "/search", search: { q: typeof q === "string" ? q : "" } }); }} >
{viewer ? ( <> + New Notifications {unread > 0 && ( )} ) : ( <> Sign in Sign up )}
); }