2023-04-17 23:00:47 -04:00
|
|
|
import { getCollection, getCollectionProducts } from 'lib/shopify';
|
|
|
|
import { Metadata } from 'next';
|
|
|
|
import { notFound } from 'next/navigation';
|
|
|
|
|
2023-04-20 11:27:18 -05:00
|
|
|
import Grid from 'components/grid';
|
|
|
|
import ProductGridItems from 'components/layout/product-grid-items';
|
2023-05-12 16:02:51 -07:00
|
|
|
import { defaultSort, sorting } from 'lib/constants';
|
2023-04-17 23:00:47 -04:00
|
|
|
|
|
|
|
export const runtime = 'edge';
|
|
|
|
|
|
|
|
export async function generateMetadata({
|
|
|
|
params
|
|
|
|
}: {
|
|
|
|
params: { collection: string };
|
|
|
|
}): Promise<Metadata> {
|
|
|
|
const collection = await getCollection(params.collection);
|
|
|
|
|
|
|
|
if (!collection) return notFound();
|
|
|
|
|
|
|
|
return {
|
|
|
|
title: collection.seo?.title || collection.title,
|
|
|
|
description:
|
2023-06-07 20:57:31 -05:00
|
|
|
collection.seo?.description || collection.description || `${collection.title} products`
|
2023-04-17 23:00:47 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-05-12 16:02:51 -07:00
|
|
|
export default async function CategoryPage({
|
|
|
|
params,
|
|
|
|
searchParams
|
|
|
|
}: {
|
|
|
|
params: { collection: string };
|
|
|
|
searchParams?: { [key: string]: string | string[] | undefined };
|
|
|
|
}) {
|
|
|
|
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 });
|
2023-04-17 23:00:47 -04:00
|
|
|
|
|
|
|
return (
|
|
|
|
<section>
|
|
|
|
{products.length === 0 ? (
|
|
|
|
<p className="py-3 text-lg">{`No products found in this collection`}</p>
|
2023-04-20 11:27:18 -05:00
|
|
|
) : (
|
2023-07-24 21:40:29 -05:00
|
|
|
<Grid className="grid-cols-1 sm:grid-cols-2 lg:grid-cols-3">
|
2023-04-20 11:27:18 -05:00
|
|
|
<ProductGridItems products={products} />
|
|
|
|
</Grid>
|
|
|
|
)}
|
2023-04-17 23:00:47 -04:00
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|