import { prisma } from '@/lib/prisma'; import { toProductDTO } from '@/lib/product'; import { fetchActivePromotions } from '@/lib/promotions'; import ProductCard from '@/components/ProductCard'; import LoadingSpinner from '@/components/LoadingSpinner'; import { Suspense } from 'react'; type SearchParams = { page?: string; }; const PRODUCTS_PER_PAGE = 20; async function ProductsGrid({ currentPage }: { currentPage: number }) { const activePromotions = await fetchActivePromotions(); const [rows, totalCount] = await Promise.all([ prisma.product.findMany({ where: { showOnPersonalised: true }, orderBy: { createdAt: 'asc' }, take: PRODUCTS_PER_PAGE, skip: (currentPage - 1) * PRODUCTS_PER_PAGE, }), prisma.product.count({ where: { showOnPersonalised: true } }), ]); const products = rows.map((p) => toProductDTO(p, activePromotions, 'personalised')); const totalPages = Math.ceil(totalCount / PRODUCTS_PER_PAGE); return { products, totalPages, totalCount, currentPage }; } export default async function ProductsPage({ searchParams }: { searchParams: SearchParams }) { const currentPage = Math.max(1, Number(searchParams.page) || 1); const totalCount = await prisma.product.count({ where: { showOnPersonalised: true } }); return (

Shop all

{totalCount} template{totalCount === 1 ? '' : 's'}

}>
); } async function ProductsGridContent({ currentPage, totalCount }: { currentPage: number; totalCount: number }) { const { products, totalPages } = await ProductsGrid({ currentPage }); return (
{products.length === 0 ? (

Nothing here yet

Templates will show up here once created.

) : (
{products.map((p) => ( ))}
{totalPages > 1 && (
{currentPage > 1 && ( ← Previous )}

Page {currentPage} of {totalPages}

{currentPage < totalPages && ( Next → )}
)}
)}
); }