| 1 | import { GitMerge, GitPullRequest, GitPullRequestClosed } from "lucide-react"; |
| 2 | import Link from "next/link |
| 3 | import { notFound } |
| 4 | |
| 5 | import { UserLink } |
| 6 | import { FromNowHoverCard } |
| 7 | import type { PullRequestFilter |
| 8 | import { |
| 9 | branchLabel, |
| 10 | pullRequestFilters, |
| 11 | } from "@/components/pull-requests/common"; |
| 12 | import { Badge } |
| 13 | import { Button, buttonVariants |
| 14 | import { createServerClient } |
| 15 | import { cn } |
| 16 | |
| 17 | const PAGE_SIZE = 20 |
| 18 | |
| 19 | export default async function |
| 20 | params, |
| 21 | searchParams, |
| 22 | }: PageProps< |
| 23 | const { username, |
| 24 | const { state, |
| 25 | |
| 26 | const filter: |
| 27 | state as PullRequestFilter |
| 28 | ) |
| 29 | ? (state as |
| 30 | : "open"; |
| 31 | |
| 32 | const client = |
| 33 | const pulls = |
| 34 | params: { |
| 35 | path: { username, |
| 36 | query: { |
| 37 | state: filter, |
| 38 | limit: PAGE_SIZE, |
| 39 | cursor: typeof cursor |
| 40 | }, |
| 41 | }, |
| 42 | }); |
| 43 | |
| 44 | if (pulls.response |
| 45 | if (!pulls.data |
| 46 | throw new Error( |
| 47 | } |
| 48 | |
| 49 | const base = |
| 50 | |
| 51 | return ( |
| 52 | <div className="flex flex-col gap-4 |
| 53 | <div className="flex flex-wrap items-center gap-2 |
| 54 | <div className="flex gap-1 |
| 55 | {pullRequestFilters.map(( |
| 56 | <Link |
| 57 | key={option} |
| 58 | href={option === |
| 59 | className={cn( |
| 60 | buttonVariants({ |
| 61 | variant: option === |
| 62 | size: "sm", |
| 63 | }), |
| 64 | "capitalize", |
| 65 | )} |
| 66 | > |
| 67 | {option} |
| 68 | </Link> |
| 69 | ))} |
| 70 | </div> |
| 71 | |
| 72 | <Button size=" |
| 73 | <Link href={ |
| 74 | <GitPullRequest data-icon=" |
| 75 | New pull request |
| 76 | </Link> |
| 77 | </Button> |
| 78 | </div> |
| 79 | |
| 80 | <div className="overflow-hidden rounded-lg border |
| 81 | {pulls.data.pullRequests |
| 82 | <p className="py-16 text-center text-sm text-muted-foreground |
| 83 | {filter === "all |
| 84 | ? "This repository has no pull requests yet." |
| 85 | : `There are no ${filter} |
| 86 | </p> |
| 87 | ) : ( |
| 88 | <ul className="divide-y |
| 89 | {pulls.data.pullRequests |
| 90 | const Icon = |
| 91 | pull.state === |
| 92 | ? GitMerge |
| 93 | : pull.state |
| 94 | ? GitPullRequestClosed |
| 95 | : GitPullRequest; |
| 96 | |
| 97 | return ( |
| 98 | <li |
| 99 | key={pull.id |
| 100 | className="flex items-start gap-3 px-4 py-3 text-sm hover:bg-muted/40" |
| 101 | > |
| 102 | <Icon |
| 103 | className={cn( |
| 104 | "mt-0.5 size-4 shrink-0", |
| 105 | pull.state === |
| 106 | pull.state === |
| 107 | pull.state === |
| 108 | )} |
| 109 | /> |
| 110 | |
| 111 | <div className="min-w-0 flex-1 |
| 112 | <Link |
| 113 | href={`${base |
| 114 | className="font-medium hover:underline" |
| 115 | > |
| 116 | {pull.title} |
| 117 | </Link> |
| 118 | {pull.draft && |
| 119 | <Badge variant=" |
| 120 | Draft |
| 121 | </Badge> |
| 122 | )} |
| 123 | <p className="truncate text-xs text-muted-foreground |
| 124 | #{pull.number} opened |
| 125 | <FromNowHoverCard date={ |
| 126 | <UserLink |
| 127 | username={pull.authorUsername |
| 128 | className="font-normal text-muted-foreground" |
| 129 | /> |
| 130 | </p> |
| 131 | </div> |
| 132 | |
| 133 | <code className="hidden shrink-0 rounded bg-muted px-1.5 py-0.5 text-xs text-muted-foreground sm:block |
| 134 | {branchLabel(pull.head |
| 135 | {" → "} |
| 136 | {pull.base.ref |
| 137 | </code> |
| 138 | </li> |
| 139 | ); |
| 140 | })} |
| 141 | </ul> |
| 142 | )} |
| 143 | </div> |
| 144 | |
| 145 | {pulls.data.nextCursor |
| 146 | <div className="flex justify-end |
| 147 | <Link |
| 148 | href={`${base |
| 149 | className={buttonVariants({ |
| 150 | > |
| 151 | Older |
| 152 | </Link> |
| 153 | </div> |
| 154 | )} |
| 155 | </div> |
| 156 | ); |
| 157 | } |