import { getCollection, getCollectionProducts } from 'lib/shopify'; import { Metadata } from 'next'; import { notFound } from 'next/navigation'; import Grid from 'components/grid'; import ProductGridItems from 'components/layout/product-grid-items'; import { defaultSort, sorting } from 'lib/constants'; export async function generateMetadata(props: { params: Promise<{ collection: string }>; }): Promise { const params = await props.params; const collection = await getCollection(params.collection); if (!collection) return notFound(); return { title: collection.seo?.title || collection.title, description: collection.seo?.description || collection.description || `${collection.title} products` }; } export default async function CategoryPage(props: { params: Promise<{ collection: string }>; searchParams?: Promise<{ [key: string]: string | string[] | undefined }>; }) { const searchParams = await props.searchParams; const params = await props.params; const { sort } = searchParams as { [key: string]: string }; const { sortKey, reverse } = sorting.find((item) => item.slug === sort) || defaultSort; const products = await getCollectionProducts({ collection: params.collection, sortKey, reverse }); return (
{products.length === 0 ? (

{`No products found in this collection`}

) : ( )}
); }