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