Skip to content
File

Blob: src/client/pages/CommitPage.tsx

typescript142 lines
1import { RepoNav } from "@/client/components/RepoNav";
2import { Card } from "@/client/components/ui/card";
3import { CommitDiffExpanderIsland } from "@/client/islands/commit-diff-expander";
4import { IslandHost } from "@/client/server/IslandHost";
5 
6type Parent = {
7 oid: string;
8 short: string;
9};
10 
11type DiffEntry = {
12 path: string;
13 changeType: "A" | "M" | "D";
14 oldOid?: string;
15 newOid?: string;
16 oldMode?: string;
17 newMode?: string;
18};
19 
20type DiffSummary = {
21 added: number;
22 modified: number;
23 deleted: number;
24 total: number;
25};
26 
27export type CommitPageProps = {
28 owner: string;
29 repo: string;
30 commitOid: string;
31 refEnc: string;
32 commitShort: string;
33 authorName: string;
34 authorEmail: string;
35 when: string;
36 parents: Parent[];
37 treeShort: string;
38 message: string;
39 diffBaseRefEnc: string;
40 diffCompareMode: "root" | "first-parent";
41 diffEntries: DiffEntry[];
42 diffSummary: DiffSummary;
43 diffTruncated: boolean;
44 diffTruncateReason: "" | "max_files" | "max_tree_pairs" | "time_budget" | "soft_budget";
45};
46 
47export function CommitPage({
48 owner,
49 repo,
50 commitOid,
51 refEnc,
52 commitShort,
53 authorName,
54 authorEmail,
55 when,
56 parents,
57 treeShort,
58 message,
59 diffBaseRefEnc,
60 diffCompareMode,
61 diffEntries,
62 diffSummary,
63 diffTruncated,
64 diffTruncateReason,
65}: CommitPageProps) {
66 return (
67 <div>
68 <RepoNav owner={owner} repo={repo} refEnc={refEnc} currentTab="commits" />
69 <span className="mb-1 inline-block text-xs font-semibold uppercase tracking-wider text-accent-500 dark:text-accent-400">
70 Commit Detail
71 </span>
72 <h2 className="font-display tracking-tight">Commit {commitShort}</h2>
73
74 <div className="space-y-4">
75 <Card>
76 <dl className="grid grid-cols-[auto_1fr] gap-x-4 gap-y-2 text-sm [&>dd]:min-w-0">
77 <dt className="font-medium text-zinc-500 dark:text-zinc-400">Author</dt>
78 <dd>
79 {authorName} &lt;{authorEmail}&gt;{" "}
80 <span className="text-zinc-500 dark:text-zinc-400">{when}</span>
81 </dd>
82 <dt className="font-medium text-zinc-500 dark:text-zinc-400">Parents</dt>
83 <dd>
84 {parents.length ? (
85 parents.map((parent, index) => (
86 <span key={parent.oid}>
87 {index > 0 ? ", " : null}
88 <a href={`/${owner}/${repo}/commit/${parent.oid}`}>{parent.short}</a>
89 </span>
90 ))
91 ) : (
92 <span className="text-zinc-500 dark:text-zinc-400">(root commit)</span>
93 )}
94 </dd>
95 <dt className="font-medium text-zinc-500 dark:text-zinc-400">Tree</dt>
96 <dd>
97 <a href={`/${owner}/${repo}/tree?ref=${refEnc}`}>{treeShort}</a>
98 </dd>
99 </dl>
100 </Card>
101 <Card>
102 <pre className="!m-0 whitespace-pre-wrap !rounded-none !border-0 !bg-transparent !p-0">
103 {message}
104 </pre>
105 </Card>
106 </div>
107
108 <h3>Files changed</h3>
109 <IslandHost
110 name="commit-diff-expander"
111 props={{
112 owner,
113 repo,
114 commitOid,
115 refEnc,
116 diffBaseRefEnc,
117 diffCompareMode,
118 diffEntries,
119 diffSummary,
120 diffTruncated,
121 diffTruncateReason,
122 parentsCount: parents.length,
123 }}
124 >
125 <CommitDiffExpanderIsland
126 owner={owner}
127 repo={repo}
128 commitOid={commitOid}
129 refEnc={refEnc}
130 diffBaseRefEnc={diffBaseRefEnc}
131 diffCompareMode={diffCompareMode}
132 diffEntries={diffEntries}
133 diffSummary={diffSummary}
134 diffTruncated={diffTruncated}
135 diffTruncateReason={diffTruncateReason}
136 parentsCount={parents.length}
137 />
138 </IslandHost>
139 </div>
140 );
141}