web/app/%5Bowner%5D/%5Brepo%5D/(tabs)/commits/page.tsxblame
View source
e4a233c1import type { Metadata } from "next";
530592e2import Link from "next/link";
bc1b2ba3import { timeAgo } from "@/lib/utils";
bc1b2ba4import { getRepoCommits } from "@/lib/grove-api";
530592e5
530592e6interface Props {
530592e7 params: Promise<{ owner: string; repo: string }>;
530592e8 searchParams: Promise<{ ref?: string }>;
530592e9}
530592e10
e4a233c11export async function generateMetadata({ params }: Props): Promise<Metadata> {
86450dc12 const { repo } = await params;
86450dc13 return { title: `Commits · ${repo}` };
e4a233c14}
e4a233c15
530592e16
530592e17export default async function CommitsPage({ params, searchParams }: Props) {
530592e18 const { owner, repo } = await params;
530592e19 const { ref: refParam } = await searchParams;
530592e20 const ref = refParam ?? "main";
530592e21
bc1b2ba22 const data = await getRepoCommits(owner, repo, ref, { limit: 50 });
530592e23
530592e24 if (!data) {
530592e25 return (
530592e26 <div className="py-10">
530592e27 <h1 className="text-lg" style={{ color: "var(--text-secondary)" }}>
530592e28 Could not load commits
530592e29 </h1>
530592e30 </div>
530592e31 );
530592e32 }
530592e33
bdf654034 if (data.commits.length === 0) {
bdf654035 return (
bdf654036 <div className="py-12 text-center">
bdf654037 <p className="text-sm" style={{ color: "var(--text-faint)" }}>
bdf654038 No commits yet on <span className="font-mono">{ref}</span>.
bdf654039 </p>
bdf654040 <p className="text-xs mt-1" style={{ color: "var(--text-faint)" }}>
bdf654041 Push your first commit to see history here.
bdf654042 </p>
bdf654043 </div>
bdf654044 );
bdf654045 }
bdf654046
530592e47 return (
530592e48 <>
530592e49 <div style={{ border: "1px solid var(--border-subtle)" }}>
530592e50 <table className="w-full text-sm">
530592e51 <tbody>
530592e52 {data.commits.map((commit: any, i: number) => {
530592e53 const hash = commit.hash;
530592e54 const subject = commit.subject ?? "";
530592e55 const authorName = commit.author?.split("<")[0]?.trim() ?? commit.author;
530592e56 const initial = authorName?.[0]?.toUpperCase() ?? "?";
530592e57 return (
530592e58 <tr
530592e59 key={commit.hash}
530592e60 className="hover-row"
530592e61 style={{
530592e62 borderTop:
530592e63 i > 0 ? "1px solid var(--divide)" : undefined,
530592e64 }}
530592e65 >
530592e66 <td className="py-2 pl-3 pr-2 w-8">
530592e67 <span
530592e68 title={commit.author}
530592e69 style={{
530592e70 display: "inline-flex",
530592e71 alignItems: "center",
530592e72 justifyContent: "center",
530592e73 width: 22,
530592e74 height: 22,
530592e75 borderRadius: "50%",
530592e76 backgroundColor: "var(--bg-inset)",
530592e77 border: "1px solid var(--border-subtle)",
530592e78 color: "var(--text-muted)",
530592e79 fontSize: "0.65rem",
530592e80 cursor: "default",
530592e81 }}
530592e82 >
530592e83 {initial}
530592e84 </span>
530592e85 </td>
530592e86 <td className="py-2 pr-3 truncate" style={{ maxWidth: 0 }}>
530592e87 <Link
530592e88 href={`/${owner}/${repo}/commit/${hash}`}
530592e89 className="hover:underline"
530592e90 style={{ color: "var(--text-primary)" }}
530592e91 >
530592e92 {subject}
530592e93 </Link>
530592e94 </td>
530592e95 <td
8a2c7d496 className="py-2 pr-3 font-mono text-xs w-16 hidden sm:table-cell"
530592e97 >
530592e98 <Link
530592e99 href={`/${owner}/${repo}/commit/${hash}`}
530592e100 style={{ color: "var(--accent)" }}
530592e101 className="hover:underline"
530592e102 >
530592e103 {hash.slice(0, 7)}
530592e104 </Link>
530592e105 </td>
530592e106 <td
530592e107 className="py-2 pr-3 text-xs w-20 text-right"
530592e108 style={{ color: "var(--text-faint)" }}
530592e109 >
530592e110 {timeAgo(commit.timestamp)}
530592e111 </td>
530592e112 </tr>
530592e113 );
530592e114 })}
530592e115 </tbody>
530592e116 </table>
530592e117 </div>
530592e118 </>
530592e119 );
530592e120}