import { AgentAvatar, Ago, Badge, Banner, Button, Dialog, Empty, Input, LayerCard } from "@refs/design-system"; import { GitBranchIcon, GitPullRequestIcon, TrashIcon } from "@refs/design-system/icons"; import { pullLink, repoLink, type BranchSummary } from "@refs/backend/contract"; import { useState } from "react"; import { Link, useFetcher } from "react-router"; import type { Route } from "./+types/repo-branches"; import { failed, formText, found, fullName, nowSeconds, refs } from "../lib/session"; const FILTER_FROM = 8; export const meta: Route.MetaFunction = ({ params }) => [{ title: `Branches · ${fullName(params)} · refs` }]; export async function loader({ params, context }: Route.LoaderArgs) { const repo = await found(refs(context).repo(fullName(params))); return { repo: fullName(params), canDelete: repo.summary.can.write, branches: await found(repo.branches()), now: nowSeconds() }; } export async function action({ request, params, context }: Route.ActionArgs) { const repo = await found(refs(context).repo(fullName(params))); const outcome = await found(repo.deleteBranch(formText(await request.formData(), "name"))); return outcome.ok ? { error: null } : failed(outcome.problem, {}); } function DeleteBranch({ name }: { name: string }) { const fetcher = useFetcher(); return ( ( )} /> Delete {name}? Commits that are only on this branch are lost. Commits that are on another branch stay. {fetcher.data?.error && } } /> ); } function BranchRow({ repo, branch, canDelete, now }: { repo: string; branch: BranchSummary; canDelete: boolean; now: number }) { const free = !branch.isDefault && branch.pull === null && branch.agent === null; return (
  • ); } function Group({ title, children }: { title: string; children: React.ReactNode }) { return (

    {title}

    {children}
    ); } export default function RepoBranches({ loaderData }: Route.ComponentProps) { const { repo, branches, canDelete, now } = loaderData; const [filter, setFilter] = useState(""); const main = branches.find((branch) => branch.isDefault); const others = branches.filter((branch) => !branch.isDefault); const shown = others.filter((branch) => branch.name.toLowerCase().includes(filter.trim().toLowerCase())); if (branches.length === 0) { return ( } title="No branches yet" description="This repository has no commits. Push a commit to create the first branch." contents={ See how to push } /> ); } return (

    Branches

    {main && (
    )} {others.length >= FILTER_FROM && setFilter(event.target.value)} />} {others.length === 0 ? ( ) : shown.length === 0 ? ( setFilter("")}>Clear the filter} /> ) : (
      {shown.map((branch) => ( ))}
    )}
    ); }