import type { Metadata } from "next"; import { db, recipes, users, eq, desc, count } from "@epicure/db"; import { Badge } from "@/components/ui/badge"; import Link from "next/link"; import { UnpublishRecipeButton } from "@/components/admin/unpublish-recipe-button"; export const metadata: Metadata = {}; const PAGE_SIZE = 100; const VISIBILITY_COLORS = { public: "default", unlisted: "outline", followers: "outline", private: "secondary", } as const; interface PageProps { searchParams: Promise<{ page?: string }>; } export default async function AdminRecipesPage({ searchParams }: PageProps) { const { page: pageParam } = await searchParams; const page = Math.max(1, parseInt(pageParam ?? "1", 10) || 1); const offset = (page - 1) * PAGE_SIZE; const [publicRecipes, totalRow] = await Promise.all([ db .select({ id: recipes.id, title: recipes.title, visibility: recipes.visibility, createdAt: recipes.createdAt, authorName: users.name, authorId: users.id, }) .from(recipes) .leftJoin(users, eq(recipes.authorId, users.id)) .where(eq(recipes.visibility, "public")) .orderBy(desc(recipes.createdAt)) .limit(PAGE_SIZE) .offset(offset), db.select({ count: count() }).from(recipes).where(eq(recipes.visibility, "public")), ]); const total = totalRow[0]?.count ?? 0; return (

Recipe Moderation

Public recipes sorted by newest. Review and decide manually.

{publicRecipes.length === 0 ? ( ) : ( publicRecipes.map((recipe) => ( )) )}
Title Author Visibility Created Link Action
No public recipes yet.
{recipe.title} {recipe.authorId ? ( {recipe.authorName ?? "Unknown"} ) : ( {recipe.authorName ?? "Unknown"} )} {recipe.visibility} {recipe.createdAt.toLocaleDateString()} View
{page > 1 && ( Previous )} {offset + publicRecipes.length < total && ( Next )}
); }