"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useState } from "react"; import { BranchIcon, CodeIcon, GearIcon, HistoryIcon, IssueOpenedIcon, PackageIcon, PlayIcon, TagIcon } from "./icons"; import { SlidingIndicator, thumbClass } from "./sliding-indicator"; /** * A repository's sections on the switcher track: they are pages, so they are links (not MetalUI Tabs), * with the switcher's raised thumb gliding under the current one. */ export function RepoTabs({ base, openIssues, releases, images, showSettings, }: { base: string; openIssues: number; releases: number; images: number; showSettings: boolean; }) { const pathname = usePathname(); const section = pathname.slice(base.length).split("/")[1] ?? ""; const tabs = [ { href: base, label: "Code", icon: CodeIcon, active: !["issues", "actions", "branches", "commits", "commit", "releases", "packages", "settings"].includes(section) }, { href: `${base}/issues`, label: "Issues", icon: IssueOpenedIcon, count: openIssues, active: section === "issues" }, { href: `${base}/actions`, label: "Actions", icon: PlayIcon, active: section === "actions" }, { href: `${base}/commits`, label: "Commits", icon: HistoryIcon, active: section === "commits" || section === "commit" }, { href: `${base}/branches`, label: "Branches", icon: BranchIcon, active: section === "branches" }, { href: `${base}/releases`, label: "Releases", icon: TagIcon, count: releases, active: section === "releases" }, { href: `${base}/packages`, label: "Packages", icon: PackageIcon, count: images, active: section === "packages" }, ...(showSettings ? [{ href: `${base}/settings`, label: "Settings", icon: GearIcon, active: section === "settings" }] : []), ]; // Move the thumb as soon as a tab is clicked instead of waiting for the next page; // the optimistic choice is dropped once the URL changes. const [clicked, setClicked] = useState<{ from: string; index: number } | null>(null); const activeIndex = clicked?.from === pathname ? clicked.index : tabs.findIndex((t) => t.active); return (
); }