CommitLog.tsx
| 1 | import type { RepositoryRow } from "../../db/index.ts"; |
| 2 | import { formatDateTime } from "../../lib/formatDate.ts"; |
| 3 | |
| 4 | import type { SessionUser } from "../../middleware/session.ts"; |
| 5 | import type { CommitEntry } from "../../services/git.ts"; |
| 6 | import { Layout } from "../layout.tsx"; |
| 7 | import { RepoHeader } from "../repos/RepoHeader.tsx"; |
| 8 | import { BranchSelector } from "./BranchSelector.tsx"; |
| 9 | import { RepoNav } from "./RepoNav.tsx"; |
| 10 | |
| 11 | interface CommitLogProps { |
| 12 | user: SessionUser | null; |
| 13 | repo: RepositoryRow; |
| 14 | ref: string; |
| 15 | commits: CommitEntry[]; |
| 16 | branches: string[]; |
| 17 | /** URL for the next (older) page, or null if this is the last page. */ |
| 18 | olderUrl: string | null; |
| 19 | /** URL for the previous (newer) page, or null if this is the first page. */ |
| 20 | newerUrl: string | null; |
| 21 | } |
| 22 | |
| 23 | export function CommitLog({ |
| 24 | user, |
| 25 | repo, |
| 26 | ref: logRef, |
| 27 | commits, |
| 28 | branches, |
| 29 | olderUrl, |
| 30 | newerUrl, |
| 31 | }: CommitLogProps) { |
| 32 | return ( |
| 33 | <Layout user={user} title={`Commits — ${repo.name}`}> |
| 34 | <div class="container"> |
| 35 | <RepoHeader repo={repo} /> |
| 36 | <RepoNav repo={repo} active="commits" user={user} /> |
| 37 | <div class="commits-header"> |
| 38 | <h2 class="section-title">Commits</h2> |
| 39 | <BranchSelector |
| 40 | repoName={repo.name} |
| 41 | branches={branches} |
| 42 | currentRef={logRef} |
| 43 | view="commits" |
| 44 | /> |
| 45 | </div> |
| 46 | {commits.length === 0 ? ( |
| 47 | <p class="text-muted">No commits yet.</p> |
| 48 | ) : ( |
| 49 | <ul class="commit-list commit-log"> |
| 50 | {commits.map((c) => ( |
| 51 | <li class="commit-item"> |
| 52 | <div class="commit-main"> |
| 53 | <a |
| 54 | href={`/${repo.name}/commit/${c.hash}`} |
| 55 | class="commit-subject" |
| 56 | > |
| 57 | {c.subject} |
| 58 | </a> |
| 59 | </div> |
| 60 | <div class="commit-meta"> |
| 61 | <span class="commit-author"> |
| 62 | {c.author} |
| 63 | </span> |
| 64 | <a |
| 65 | href={`/${repo.name}/commit/${c.hash}`} |
| 66 | class="commit-hash mono" |
| 67 | > |
| 68 | {c.hash.slice(0, 7)} |
| 69 | </a> |
| 70 | <time class="commit-date" datetime={c.date}> |
| 71 | {formatDateTime(c.date)} |
| 72 | </time> |
| 73 | </div> |
| 74 | </li> |
| 75 | ))} |
| 76 | </ul> |
| 77 | )} |
| 78 | {(newerUrl || olderUrl) && ( |
| 79 | <nav |
| 80 | class="commit-cursor-nav" |
| 81 | aria-label="Commit history navigation" |
| 82 | > |
| 83 | <div class="commit-cursor-prev"> |
| 84 | {newerUrl && ( |
| 85 | <a href={newerUrl} class="pagination-btn"> |
| 86 | ← Newer |
| 87 | </a> |
| 88 | )} |
| 89 | </div> |
| 90 | <div class="commit-cursor-next"> |
| 91 | {olderUrl && ( |
| 92 | <a href={olderUrl} class="pagination-btn"> |
| 93 | Older → |
| 94 | </a> |
| 95 | )} |
| 96 | </div> |
| 97 | </nav> |
| 98 | )} |
| 99 | </div> |
| 100 | </Layout> |
| 101 | ); |
| 102 | } |
| 103 |