import { Suspense } from "react"; import { connection } from "next/server"; import Link from "next/link"; import { getPublicRepositories, getPublicUsers } from "@/actions/repositories"; import { Button } from "@/components/ui/button"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Star, GitBranch, ChevronLeft, ChevronRight, Compass, Clock, Flame, Sparkles, Users, BookOpen } from "lucide-react"; import { formatDistanceToNow } from "date-fns"; const REPO_SORT_OPTIONS = [ { value: "stars", label: "Most stars", icon: Flame }, { value: "updated", label: "Recently updated", icon: Clock }, { value: "created", label: "Newest", icon: Sparkles }, ] as const; const USER_SORT_OPTIONS = [ { value: "newest", label: "Newest", icon: Sparkles }, { value: "oldest", label: "Oldest", icon: Clock }, ] 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}
)} ); } async function UserGrid({ sortBy, page, perPage }: { sortBy: "newest" | "oldest"; page: number; perPage: number }) { await connection(); const offset = (page - 1) * perPage; const { users, hasMore } = await getPublicUsers(sortBy, perPage, offset); if (users.length === 0) { return (

No users yet

Be the first to join!

); } return ( <>
{users.map((user) => (
{user.name?.charAt(0).toUpperCase() || "U"}

{user.name}

@{user.username}

{user.bio &&

{user.bio}

}
{user.repoCount} {user.repoCount === 1 ? "repository" : "repositories"}
))}
{(page > 1 || hasMore) && (
Page {page}
)} ); } function GridSkeleton() { return (
{[...Array(5)].map((_, i) => (
))}
); } function UserGridSkeleton() { return (
{[...Array(6)].map((_, i) => (
))}
); } export default async function ExplorePage({ searchParams, }: { searchParams: Promise<{ tab?: string; sort?: string; page?: string; usort?: string; upage?: string }>; }) { const { tab, sort: sortParam, page: pageParam, usort: usortParam, upage: upageParam } = await searchParams; const activeTab = tab === "users" ? "users" : "repositories"; const sortBy = (["stars", "updated", "created"].includes(sortParam || "") ? sortParam : "stars") as "stars" | "updated" | "created"; const page = parseInt(pageParam || "1", 10); const userSortBy = (["newest", "oldest"].includes(usortParam || "") ? usortParam : "newest") as "newest" | "oldest"; const userPage = parseInt(upageParam || "1", 10); const perPage = 20; return (

Explore

Discover repositories and users from the community

Repositories Users
{REPO_SORT_OPTIONS.map(({ value, label, icon: Icon }) => ( ))}
}>
{USER_SORT_OPTIONS.map(({ value, label, icon: Icon }) => ( ))}
}>
); }