Skip to content
refs
History
91 lines · 4.4 KBRaw
1import { Ago, Empty, LayerCard, LineBadge, LinkButton, Tabs } from "@refs/design-system";
2import { ArrowRightIcon, ChatCircleIcon, GitPullRequestIcon, PlusIcon } from "@refs/design-system/icons";
3import { pullLink } from "@refs/backend/contract";
4
5import { Link, useNavigate } from "react-router";
6import type { Route } from "./+types/repo-pulls";
7import { PullStatusIcon } from "../components/pull-status";
8import { Opener, openerOf } from "../components/timeline";
9import { found, signedIn, fullName, nowSeconds } from "../lib/session";
10
11export const meta: Route.MetaFunction = ({ params }) => [{ title: `Pull requests · ${fullName(params)} · refs` }];
12
13export async function loader({ request, params, context }: Route.LoaderArgs) {
14 const status = new URL(request.url).searchParams.get("state") === "closed" ? ("closed" as const) : ("open" as const);
15 const repo = await found(signedIn(context).repo(fullName(params)));
16 const list = await found(repo.pulls({ status }));
17 return { repo: fullName(params), status, ...list, now: nowSeconds() };
18}
19
20export default function RepoPulls({ loaderData }: Route.ComponentProps) {
21 const { repo, status, items, counts, now } = loaderData;
22 const navigate = useNavigate();
23 return (
24 <div className="flex flex-col gap-4">
25 <div className="flex flex-wrap items-center justify-between gap-3">
26 <Tabs
27 variant="segmented"
28 value={status}
29 onValueChange={(value) => navigate(value === "closed" ? `/${repo}/pulls?state=closed` : `/${repo}/pulls`)}
30 tabs={[
31 { value: "open", label: `${counts.open} Open` },
32 { value: "closed", label: `${counts.closed} Closed` },
33 ]}
34 />
35 <LinkButton variant="primary" href={`/${repo}/compare`} icon={<PlusIcon />}>
36 New pull request
37 </LinkButton>
38 </div>
39 {items.length === 0 ? (
40 <Empty
41 icon={<GitPullRequestIcon size={40} />}
42 title={status === "open" ? "No open pull requests" : "No closed pull requests"}
43 description={status === "open" ? "Open one to propose merging a branch." : "Merged and closed pull requests show up here."}
44 contents={
45 status === "open" && (
46 <LinkButton variant="secondary" href={`/${repo}/compare`} icon={<PlusIcon />}>
47 New pull request
48 </LinkButton>
49 )
50 }
51 />
52 ) : (
53 <LayerCard>
54 <ul className="m-0 list-none p-0">
55 {items.map((pull) => (
56 <li key={pull.number} className="flex items-start gap-3 px-4 py-3 shadow-[inset_0_-1px_0_var(--hairline)] transition-colors duration-150 last:shadow-none hover:bg-hover">
57 <span className="mt-0.5">
58 <PullStatusIcon status={pull.status} size={16} />
59 </span>
60 <div className="flex min-w-0 flex-1 flex-col gap-1">
61 <div className="flex flex-wrap items-baseline gap-x-2">
62 <Link to={`${pullLink(repo, pull.number)}/reasoning`} className="font-semibold text-ink hover:text-accent-text">
63 {pull.title}
64 </Link>
65 <span className="text-compact text-faint tabular-nums">#{pull.number}</span>
66 </div>
67 <span className="flex flex-wrap items-center gap-x-2 gap-y-1 text-compact text-muted">
68 <span className="inline-flex max-w-full items-center gap-1.5">
69 <LineBadge name={pull.head} />
70 <ArrowRightIcon size={10} aria-label="into" className="shrink-0 text-faint" />
71 <LineBadge name={pull.base} main />
72 </span>
73 <Opener by={openerOf(pull)} />
74 <span>
75 {pull.status === "open" ? "opened" : pull.status} <Ago at={pull.status === "open" ? pull.createdAt : (pull.closedAt ?? pull.createdAt)} now={now} />
76 </span>
77 </span>
78 </div>
79 {pull.comments > 0 && (
80 <Link to={pullLink(repo, pull.number)} className="flex shrink-0 items-center gap-1 text-compact text-muted tabular-nums hover:text-accent-text" aria-label={`${pull.comments} comments`}>
81 <ChatCircleIcon size={14} /> {pull.comments}
82 </Link>
83 )}
84 </li>
85 ))}
86 </ul>
87 </LayerCard>
88 )}
89 </div>
90 );
91}