import { Suspense } from "react"; import { connection } from "next/server"; import Link from "next/link"; import { getPublicRepositories } from "@/actions/repositories"; import { Button } from "@/components/ui/button"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Star, GitBranch, ChevronLeft, ChevronRight, Compass, Clock, Flame, Sparkles, Loader2 } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; const SORT_OPTIONS = [ { value: "stars", label: "Most stars", icon: Flame }, { value: "updated", label: "Recently updated", icon: Clock }, { value: "created", label: "Newest", icon: Sparkles }, ] as const; async function RepoGrid({ sortBy, page, perPage }: { sortBy: "stars" | "updated" | "created"; page: number; perPage: number }) { await connection(); const offset = (page - 1) * perPage; const { repos, hasMore } = await getPublicRepositories(sortBy, perPage, offset); if (repos.length === 0) { return (

No repositories yet

Be the first to create a public repository!

); } return ( <>
{repos.map((repo) => (
{repo.owner.name?.charAt(0).toUpperCase() || "U"}
{repo.owner.username} / {repo.name}
{repo.description &&

{repo.description}

}
{repo.starCount}
Updated {formatDistanceToNow(new Date(repo.updatedAt), { addSuffix: true })}
))}
{(page > 1 || hasMore) && (
Page {page}
)} ); } function RepoGridSkeleton() { return (
{[...Array(5)].map((_, i) => (
))}
); } export default async function ExplorePage({ searchParams }: { searchParams: Promise<{ sort?: string; page?: string }> }) { const { sort: sortParam, page: pageParam } = await searchParams; const sortBy = (["stars", "updated", "created"].includes(sortParam || "") ? sortParam : "stars") as "stars" | "updated" | "created"; const page = parseInt(pageParam || "1", 10); const perPage = 20; return (

Explore

Discover public repositories from the community

{SORT_OPTIONS.map(({ value, label, icon: Icon }) => ( ))}
}>
); }