import type { ShopifyCollection } from "@reacteditor/field-shopify"; import { useCollectionProducts } from "@/editor/hooks/use-shopify-collections"; import { ProductCard } from "./product-card"; import { Typography } from "@/editor/theme/Typography"; import { Skeleton } from "@/components/ui/skeleton"; export type CollectionProps = { collection: ShopifyCollection | null; showDescription: "yes" | "no"; }; export function CollectionView({ collection: selected, showDescription, }: CollectionProps) { const handle = selected?.handle ?? ""; const { collection, loading } = useCollectionProducts(handle, { first: 24 }); if (!selected) { return (
{showDescription === "yes" ? ( ) : null}
{Array.from({ length: 8 }).map((_, i) => ( ))}
); } const products = (collection?.products as any[] | undefined) ?? []; const description = collection?.description ?? selected.description; return (

Collection

{collection?.title ?? selected.title} {showDescription === "yes" && description ? ( {description} ) : null}
{loading ? Array.from({ length: 8 }).map((_, i) => ( )) : products.map((p: any) => )}
{!loading && products.length === 0 ? (
This collection has no products yet.
) : null}
); }