2023-04-17 23:00:47 -04:00
|
|
|
import { getCollectionProducts } from 'lib/shopify';
|
|
|
|
import Link from 'next/link';
|
2023-07-24 21:40:29 -05:00
|
|
|
import { GridTileImage } from './grid/tile';
|
2023-04-17 23:00:47 -04:00
|
|
|
|
|
|
|
export async function Carousel() {
|
|
|
|
// Collections that start with `hidden-*` are hidden from the search page.
|
2023-05-12 16:02:51 -07:00
|
|
|
const products = await getCollectionProducts({ collection: 'hidden-homepage-carousel' });
|
2023-04-17 23:00:47 -04:00
|
|
|
|
|
|
|
if (!products?.length) return null;
|
|
|
|
|
2023-08-03 21:17:02 -05:00
|
|
|
// Purposefully duplicating products to make the carousel loop and not run out of products on wide screens.
|
|
|
|
const carouselProducts = [...products, ...products, ...products];
|
|
|
|
|
2023-04-17 23:00:47 -04:00
|
|
|
return (
|
2024-07-28 23:26:03 -05:00
|
|
|
<div className="w-full overflow-x-auto pb-6 pt-1">
|
2023-08-02 21:07:35 -05:00
|
|
|
<ul className="flex animate-carousel gap-4">
|
2023-08-03 21:17:02 -05:00
|
|
|
{carouselProducts.map((product, i) => (
|
2023-08-02 21:07:35 -05:00
|
|
|
<li
|
2023-04-17 23:00:47 -04:00
|
|
|
key={`${product.handle}${i}`}
|
2023-08-02 21:07:35 -05:00
|
|
|
className="relative aspect-square h-[30vh] max-h-[275px] w-2/3 max-w-[475px] flex-none md:w-1/3"
|
2023-04-17 23:00:47 -04:00
|
|
|
>
|
2023-08-02 21:07:35 -05:00
|
|
|
<Link href={`/product/${product.handle}`} className="relative h-full w-full">
|
|
|
|
<GridTileImage
|
|
|
|
alt={product.title}
|
|
|
|
label={{
|
|
|
|
title: product.title,
|
|
|
|
amount: product.priceRange.maxVariantPrice.amount,
|
|
|
|
currencyCode: product.priceRange.maxVariantPrice.currencyCode
|
|
|
|
}}
|
|
|
|
src={product.featuredImage?.url}
|
|
|
|
fill
|
|
|
|
sizes="(min-width: 1024px) 25vw, (min-width: 768px) 33vw, 50vw"
|
|
|
|
/>
|
|
|
|
</Link>
|
|
|
|
</li>
|
2023-04-17 23:00:47 -04:00
|
|
|
))}
|
2023-08-02 21:07:35 -05:00
|
|
|
</ul>
|
2023-04-17 23:00:47 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|