"use client"; import Link from "next/link"; import { usePathname, useRouter } from "next/navigation"; import type { ComponentType, SVGProps } from "react"; import { Avatar as MuAvatar, Menu, MenuItem, MenuSeparator, Sidebar } from "@unlocalhosted/metalui"; import { logoutAction } from "@/app/actions/auth"; import type { Theme } from "@/lib/theme"; import { BRAND, LogoMark } from "./brand"; import { ChevronsUpDownIcon, CompassIcon, GearIcon, HomeIcon, KeyIcon, MenuIcon, OrganizationIcon, PersonIcon, PlusIcon, RepoIcon, ShieldLockIcon, SignOutIcon } from "./icons"; import { ThemeToggle } from "./theme-toggle"; import { RepoAvatar } from "./ui"; type Item = { href: string; label: string; icon: ComponentType>; match: (p: string) => boolean }; export type SidebarRepo = { owner: string; name: string; imageVersion: number | null }; export type SidebarViewer = { username: string; name: string }; function navItems(username: string): Item[] { return [ { href: "/", label: "Overview", icon: HomeIcon, match: (p) => p === "/" }, { href: `/${username}`, label: "Repositories", icon: RepoIcon, match: (p) => p === `/${username}` }, { href: "/explore", label: "Explore", icon: CompassIcon, match: (p) => p.startsWith("/explore") }, { href: "/settings/profile", label: "Settings", icon: GearIcon, match: (p) => p.startsWith("/settings") }, ]; } /** The account's rows: who you are, then where your account lives, then Sign Out (last, on its own). */ function AccountMenuItems({ viewer }: { viewer: SidebarViewer }) { const router = useRouter(); return ( <> } onSelect={() => router.push(`/${viewer.username}`)}> Your Profile } onSelect={() => router.push("/settings/organizations")}> Your Organizations } onSelect={() => router.push("/settings/profile")}> Settings } onSelect={() => router.push("/settings/keys")}> SSH Keys } onSelect={() => router.push("/settings/tokens")}> API Tokens } onSelect={() => void logoutAction()}> Sign Out ); } /** Left rail for signed-in users: MetalUI's Sidebar with the account menu, the places, and repository shortcuts. */ export function AppSidebar({ viewer, repos, theme }: { viewer: SidebarViewer; repos: SidebarRepo[]; theme: Theme }) { const pathname = usePathname(); return ( ); } /** The same places as a menu, for small screens. */ export function MobileNav({ viewer }: { viewer: SidebarViewer }) { const router = useRouter(); return ( } > {navItems(viewer.username).map((item) => ( } onSelect={() => router.push(item.href)}> {item.label} ))} ); }