"use client"; import { useRouter } from "next/navigation"; import { Select } from "@unlocalhosted/metalui"; import { BranchIcon, RepoIcon } from "@/components/icons"; type Side = { baseRepo: string; base: string; headRepo: string; head: string | null }; /** * The two sides of a comparison: where the changes go (base) and where they come from (head). With * forks around, each side also names its repository ("owner/name"), and the page belongs to the base's. */ export function CompareSelect({ branches, headBranches, repos, current }: { branches: string[]; headBranches: string[]; repos: string[]; current: Side }) { const router = useRouter(); const options = (names: string[]) => names.map((b) => ({ value: b, label: b, lead: })); const repoOptions = repos.map((r) => ({ value: r, label: r, lead: })); const go = (next: Side) => { const query = new URLSearchParams({ ...(next.base ? { base: next.base } : {}), ...(next.headRepo !== next.baseRepo ? { head_repo: next.headRepo } : {}), ...(next.head ? { head: next.head } : {}), }); router.push(`/${next.baseRepo}/compare?${query}`); }; const forks = repos.length > 1; return (
base {forks && ( go({ ...current, base: v })} /> ← compare {forks && ( go({ ...current, head: v })} />
); }