PatchList.tsx
| 1 | import type { PatchRow, RepositoryRow } from "../../db/index.ts"; |
| 2 | import { displayName } from "../../lib/users.ts"; |
| 3 | import type { SessionUser } from "../../middleware/session.ts"; |
| 4 | import { Layout } from "../layout.tsx"; |
| 5 | import { Pagination, type PaginationInfo } from "../Pagination.tsx"; |
| 6 | import { RepoHeader } from "../repos/RepoHeader.tsx"; |
| 7 | import { RepoNav } from "../repos/RepoNav.tsx"; |
| 8 | |
| 9 | interface PatchListProps { |
| 10 | user: SessionUser | null; |
| 11 | repo: RepositoryRow; |
| 12 | patches: (PatchRow & { author_username: string })[]; |
| 13 | status: string; |
| 14 | counts: Record<string, number>; |
| 15 | pagination: PaginationInfo; |
| 16 | } |
| 17 | |
| 18 | export function PatchList({ |
| 19 | user, |
| 20 | repo, |
| 21 | patches, |
| 22 | status, |
| 23 | counts, |
| 24 | pagination, |
| 25 | }: PatchListProps) { |
| 26 | return ( |
| 27 | <Layout user={user} title={`Patches — ${repo.name}`}> |
| 28 | <div class="container"> |
| 29 | <RepoHeader repo={repo} /> |
| 30 | <RepoNav repo={repo} active="patches" user={user} /> |
| 31 | <div class="list-header"> |
| 32 | <div class="list-header-tabs"> |
| 33 | <a |
| 34 | href={`/${repo.name}/patches?status=open`} |
| 35 | class={`list-tab${status === "open" ? " active" : ""}`} |
| 36 | > |
| 37 | Open{" "} |
| 38 | {(counts.open ?? 0) > 0 && ( |
| 39 | <span class="tab-count">{counts.open}</span> |
| 40 | )} |
| 41 | </a> |
| 42 | <a |
| 43 | href={`/${repo.name}/patches?status=merged`} |
| 44 | class={`list-tab${status === "merged" ? " active" : ""}`} |
| 45 | > |
| 46 | Merged{" "} |
| 47 | {(counts.merged ?? 0) > 0 && ( |
| 48 | <span class="tab-count">{counts.merged}</span> |
| 49 | )} |
| 50 | </a> |
| 51 | <a |
| 52 | href={`/${repo.name}/patches?status=closed`} |
| 53 | class={`list-tab${status === "closed" ? " active" : ""}`} |
| 54 | > |
| 55 | Closed{" "} |
| 56 | {(counts.closed ?? 0) > 0 && ( |
| 57 | <span class="tab-count">{counts.closed}</span> |
| 58 | )} |
| 59 | </a> |
| 60 | </div> |
| 61 | {user && ( |
| 62 | <a |
| 63 | href={`/${repo.name}/patches/new`} |
| 64 | class="btn btn-primary btn-sm" |
| 65 | > |
| 66 | Upload patch |
| 67 | </a> |
| 68 | )} |
| 69 | </div> |
| 70 | {patches.length === 0 ? ( |
| 71 | <div class="empty-state"> |
| 72 | <p>No {status} patches.</p> |
| 73 | </div> |
| 74 | ) : ( |
| 75 | <ul class="issue-list"> |
| 76 | {patches.map((patch) => ( |
| 77 | <li class="issue-item"> |
| 78 | <div class="issue-main"> |
| 79 | <span |
| 80 | class={`patch-status-dot ${patch.status}`} |
| 81 | /> |
| 82 | <a |
| 83 | href={`/${repo.name}/patches/${patch.number}`} |
| 84 | class="issue-title" |
| 85 | > |
| 86 | {patch.title} |
| 87 | </a> |
| 88 | <span class="issue-number"> |
| 89 | #{patch.number} |
| 90 | </span> |
| 91 | </div> |
| 92 | <div class="issue-meta"> |
| 93 | <span> |
| 94 | by {displayName(patch.author_username)} |
| 95 | </span> |
| 96 | <time datetime={patch.created_at}> |
| 97 | {new Date( |
| 98 | patch.created_at, |
| 99 | ).toLocaleDateString()} |
| 100 | </time> |
| 101 | </div> |
| 102 | </li> |
| 103 | ))} |
| 104 | </ul> |
| 105 | )} |
| 106 | <Pagination {...pagination} /> |
| 107 | </div> |
| 108 | </Layout> |
| 109 | ); |
| 110 | } |
| 111 |