web/app/%5Bowner%5D/%5Brepo%5D/(tabs)/commits/page.tsxblame
View source
e4a233c1import type { Metadata } from "next";
530592e2import Link from "next/link";
530592e3import { groveApiUrl, timeAgo } from "@/lib/utils";
530592e4
530592e5interface Props {
530592e6 params: Promise<{ owner: string; repo: string }>;
530592e7 searchParams: Promise<{ ref?: string }>;
530592e8}
530592e9
e4a233c10export async function generateMetadata({ params }: Props): Promise<Metadata> {
86450dc11 const { repo } = await params;
86450dc12 return { title: `Commits · ${repo}` };
e4a233c13}
e4a233c14
530592e15async function getCommits(owner: string, repo: string, ref: string) {
530592e16 const res = await fetch(
530592e17 `${groveApiUrl}/api/repos/${owner}/${repo}/commits/${ref}?limit=50`,
530592e18 { cache: "no-store" }
530592e19 );
530592e20 if (!res.ok) return null;
530592e21 return res.json();
530592e22}
530592e23
530592e24export default async function CommitsPage({ params, searchParams }: Props) {
530592e25 const { owner, repo } = await params;
530592e26 const { ref: refParam } = await searchParams;
530592e27 const ref = refParam ?? "main";
530592e28
530592e29 const data = await getCommits(owner, repo, ref);
530592e30
530592e31 if (!data) {
530592e32 return (
530592e33 <div className="py-10">
530592e34 <h1 className="text-lg" style={{ color: "var(--text-secondary)" }}>
530592e35 Could not load commits
530592e36 </h1>
530592e37 </div>
530592e38 );
530592e39 }
530592e40
bdf654041 if (data.commits.length === 0) {
bdf654042 return (
bdf654043 <div className="py-12 text-center">
bdf654044 <p className="text-sm" style={{ color: "var(--text-faint)" }}>
bdf654045 No commits yet on <span className="font-mono">{ref}</span>.
bdf654046 </p>
bdf654047 <p className="text-xs mt-1" style={{ color: "var(--text-faint)" }}>
bdf654048 Push your first commit to see history here.
bdf654049 </p>
bdf654050 </div>
bdf654051 );
bdf654052 }
bdf654053
530592e54 return (
530592e55 <>
530592e56 <div style={{ border: "1px solid var(--border-subtle)" }}>
530592e57 <table className="w-full text-sm">
530592e58 <tbody>
530592e59 {data.commits.map((commit: any, i: number) => {
530592e60 const hash = commit.hash;
530592e61 const subject = commit.subject ?? "";
530592e62 const authorName = commit.author?.split("<")[0]?.trim() ?? commit.author;
530592e63 const initial = authorName?.[0]?.toUpperCase() ?? "?";
530592e64 return (
530592e65 <tr
530592e66 key={commit.hash}
530592e67 className="hover-row"
530592e68 style={{
530592e69 borderTop:
530592e70 i > 0 ? "1px solid var(--divide)" : undefined,
530592e71 }}
530592e72 >
530592e73 <td className="py-2 pl-3 pr-2 w-8">
530592e74 <span
530592e75 title={commit.author}
530592e76 style={{
530592e77 display: "inline-flex",
530592e78 alignItems: "center",
530592e79 justifyContent: "center",
530592e80 width: 22,
530592e81 height: 22,
530592e82 borderRadius: "50%",
530592e83 backgroundColor: "var(--bg-inset)",
530592e84 border: "1px solid var(--border-subtle)",
530592e85 color: "var(--text-muted)",
530592e86 fontSize: "0.65rem",
530592e87 cursor: "default",
530592e88 }}
530592e89 >
530592e90 {initial}
530592e91 </span>
530592e92 </td>
530592e93 <td className="py-2 pr-3 truncate" style={{ maxWidth: 0 }}>
530592e94 <Link
530592e95 href={`/${owner}/${repo}/commit/${hash}`}
530592e96 className="hover:underline"
530592e97 style={{ color: "var(--text-primary)" }}
530592e98 >
530592e99 {subject}
530592e100 </Link>
530592e101 </td>
530592e102 <td
8a2c7d4103 className="py-2 pr-3 font-mono text-xs w-16 hidden sm:table-cell"
530592e104 >
530592e105 <Link
530592e106 href={`/${owner}/${repo}/commit/${hash}`}
530592e107 style={{ color: "var(--accent)" }}
530592e108 className="hover:underline"
530592e109 >
530592e110 {hash.slice(0, 7)}
530592e111 </Link>
530592e112 </td>
530592e113 <td
530592e114 className="py-2 pr-3 text-xs w-20 text-right"
530592e115 style={{ color: "var(--text-faint)" }}
530592e116 >
530592e117 {timeAgo(commit.timestamp)}
530592e118 </td>
530592e119 </tr>
530592e120 );
530592e121 })}
530592e122 </tbody>
530592e123 </table>
530592e124 </div>
530592e125 </>
530592e126 );
530592e127}