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