| e4a233c | | | 1 | import type { Metadata } from "next"; |
| 530592e | | | 2 | import Link from "next/link"; |
| bc1b2ba | | | 3 | import { timeAgo } from "@/lib/utils"; |
| bc1b2ba | | | 4 | import { getRepoCommits } from "@/lib/grove-api"; |
| 530592e | | | 5 | |
| 530592e | | | 6 | interface Props { |
| 530592e | | | 7 | params: Promise<{ owner: string; repo: string }>; |
| 530592e | | | 8 | searchParams: Promise<{ ref?: string }>; |
| 530592e | | | 9 | } |
| 530592e | | | 10 | |
| e4a233c | | | 11 | export async function generateMetadata({ params }: Props): Promise<Metadata> { |
| 86450dc | | | 12 | const { repo } = await params; |
| 86450dc | | | 13 | return { title: `Commits · ${repo}` }; |
| e4a233c | | | 14 | } |
| e4a233c | | | 15 | |
| 530592e | | | 16 | |
| 530592e | | | 17 | export default async function CommitsPage({ params, searchParams }: Props) { |
| 530592e | | | 18 | const { owner, repo } = await params; |
| 530592e | | | 19 | const { ref: refParam } = await searchParams; |
| 530592e | | | 20 | const ref = refParam ?? "main"; |
| 530592e | | | 21 | |
| bc1b2ba | | | 22 | const data = await getRepoCommits(owner, repo, ref, { limit: 50 }); |
| 530592e | | | 23 | |
| 530592e | | | 24 | if (!data) { |
| 530592e | | | 25 | return ( |
| 530592e | | | 26 | <div className="py-10"> |
| 530592e | | | 27 | <h1 className="text-lg" style={{ color: "var(--text-secondary)" }}> |
| 530592e | | | 28 | Could not load commits |
| 530592e | | | 29 | </h1> |
| 530592e | | | 30 | </div> |
| 530592e | | | 31 | ); |
| 530592e | | | 32 | } |
| 530592e | | | 33 | |
| bdf6540 | | | 34 | if (data.commits.length === 0) { |
| bdf6540 | | | 35 | return ( |
| bdf6540 | | | 36 | <div className="py-12 text-center"> |
| bdf6540 | | | 37 | <p className="text-sm" style={{ color: "var(--text-faint)" }}> |
| bdf6540 | | | 38 | No commits yet on <span className="font-mono">{ref}</span>. |
| bdf6540 | | | 39 | </p> |
| bdf6540 | | | 40 | <p className="text-xs mt-1" style={{ color: "var(--text-faint)" }}> |
| bdf6540 | | | 41 | Push your first commit to see history here. |
| bdf6540 | | | 42 | </p> |
| bdf6540 | | | 43 | </div> |
| bdf6540 | | | 44 | ); |
| bdf6540 | | | 45 | } |
| bdf6540 | | | 46 | |
| 530592e | | | 47 | return ( |
| 530592e | | | 48 | <> |
| 530592e | | | 49 | <div style={{ border: "1px solid var(--border-subtle)" }}> |
| 530592e | | | 50 | <table className="w-full text-sm"> |
| 530592e | | | 51 | <tbody> |
| 530592e | | | 52 | {data.commits.map((commit: any, i: number) => { |
| 530592e | | | 53 | const hash = commit.hash; |
| 530592e | | | 54 | const subject = commit.subject ?? ""; |
| 530592e | | | 55 | const authorName = commit.author?.split("<")[0]?.trim() ?? commit.author; |
| 530592e | | | 56 | const initial = authorName?.[0]?.toUpperCase() ?? "?"; |
| 530592e | | | 57 | return ( |
| 530592e | | | 58 | <tr |
| 530592e | | | 59 | key={commit.hash} |
| 530592e | | | 60 | className="hover-row" |
| 530592e | | | 61 | style={{ |
| 530592e | | | 62 | borderTop: |
| 530592e | | | 63 | i > 0 ? "1px solid var(--divide)" : undefined, |
| 530592e | | | 64 | }} |
| 530592e | | | 65 | > |
| 530592e | | | 66 | <td className="py-2 pl-3 pr-2 w-8"> |
| 530592e | | | 67 | <span |
| 530592e | | | 68 | title={commit.author} |
| 530592e | | | 69 | style={{ |
| 530592e | | | 70 | display: "inline-flex", |
| 530592e | | | 71 | alignItems: "center", |
| 530592e | | | 72 | justifyContent: "center", |
| 530592e | | | 73 | width: 22, |
| 530592e | | | 74 | height: 22, |
| 530592e | | | 75 | borderRadius: "50%", |
| 530592e | | | 76 | backgroundColor: "var(--bg-inset)", |
| 530592e | | | 77 | border: "1px solid var(--border-subtle)", |
| 530592e | | | 78 | color: "var(--text-muted)", |
| 530592e | | | 79 | fontSize: "0.65rem", |
| 530592e | | | 80 | cursor: "default", |
| 530592e | | | 81 | }} |
| 530592e | | | 82 | > |
| 530592e | | | 83 | {initial} |
| 530592e | | | 84 | </span> |
| 530592e | | | 85 | </td> |
| 530592e | | | 86 | <td className="py-2 pr-3 truncate" style={{ maxWidth: 0 }}> |
| 530592e | | | 87 | <Link |
| 530592e | | | 88 | href={`/${owner}/${repo}/commit/${hash}`} |
| 530592e | | | 89 | className="hover:underline" |
| 530592e | | | 90 | style={{ color: "var(--text-primary)" }} |
| 530592e | | | 91 | > |
| 530592e | | | 92 | {subject} |
| 530592e | | | 93 | </Link> |
| 530592e | | | 94 | </td> |
| 530592e | | | 95 | <td |
| 8a2c7d4 | | | 96 | className="py-2 pr-3 font-mono text-xs w-16 hidden sm:table-cell" |
| 530592e | | | 97 | > |
| 530592e | | | 98 | <Link |
| 530592e | | | 99 | href={`/${owner}/${repo}/commit/${hash}`} |
| 530592e | | | 100 | style={{ color: "var(--accent)" }} |
| 530592e | | | 101 | className="hover:underline" |
| 530592e | | | 102 | > |
| 530592e | | | 103 | {hash.slice(0, 7)} |
| 530592e | | | 104 | </Link> |
| 530592e | | | 105 | </td> |
| 530592e | | | 106 | <td |
| 530592e | | | 107 | className="py-2 pr-3 text-xs w-20 text-right" |
| 530592e | | | 108 | style={{ color: "var(--text-faint)" }} |
| 530592e | | | 109 | > |
| 530592e | | | 110 | {timeAgo(commit.timestamp)} |
| 530592e | | | 111 | </td> |
| 530592e | | | 112 | </tr> |
| 530592e | | | 113 | ); |
| 530592e | | | 114 | })} |
| 530592e | | | 115 | </tbody> |
| 530592e | | | 116 | </table> |
| 530592e | | | 117 | </div> |
| 530592e | | | 118 | </> |
| 530592e | | | 119 | ); |
| 530592e | | | 120 | } |