import { Suspense } from "react";
import { notFound } from "next/navigation";
import Link from "next/link";
import { getRepository, getRepoCommits, getRepoBranches } from "@/actions/repositories";
import { BranchSelector } from "@/components/branch-selector";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Avatar, AvatarFallback } from "@/components/ui/avatar";
import { Lock, Globe, GitCommit, ChevronLeft, ChevronRight } from "lucide-react";
import { formatDistanceToNow } from "date-fns";
async function CommitsList({
username,
repoName,
branch,
page,
perPage,
}: {
username: string;
repoName: string;
branch: string;
page: number;
perPage: number;
}) {
const skip = (page - 1) * perPage;
const { commits, hasMore } = await getRepoCommits(username, repoName, branch, perPage, skip);
if (commits.length === 0) {
return (
No commits yet
This branch doesn't have any commits.
);
}
return (
<>
{commits.map((commit) => (
{commit.author.name.charAt(0).toUpperCase()}
{commit.message.split("\n")[0]}
{commit.author.name}
committed
{formatDistanceToNow(new Date(commit.timestamp), { addSuffix: true })}
{commit.oid.slice(0, 7)}
))}
{(page > 1 || hasMore) && (
Page {page}
)}
>
);
}
function CommitsSkeleton() {
return (
{[...Array(5)].map((_, i) => (
))}
);
}
export default async function CommitsPage({
params,
searchParams,
}: {
params: Promise<{ username: string; repo: string; branch?: string[] }>;
searchParams: Promise<{ page?: string }>;
}) {
const { username, repo: repoName, branch: branchSegments } = await params;
const { page: pageParam } = await searchParams;
const [repo, branches] = await Promise.all([getRepository(username, repoName), getRepoBranches(username, repoName)]);
if (!repo) {
notFound();
}
const branch = branchSegments?.[0] || repo.defaultBranch;
const page = parseInt(pageParam || "1", 10);
const perPage = 30;
return (
{username}
/
{repoName}
{repo.visibility === "private" ? (
<>
Private
>
) : (
<>
Public
>
)}
);
}