import { ComponentConfig } from "@reacteditor/core"; import { FolderOpen } from "lucide-react"; 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"; export type CollectionProps = { collection: ShopifyCollection | null; showDescription: "yes" | "no"; }; function CollectionView({ collection: selected, showDescription, }: CollectionProps) { const handle = selected?.handle ?? ""; const { collection, loading } = useCollectionProducts(handle, { first: 24 }); if (!selected) { return (
Pick a collection to render this page.
); } // The hook flattens collection.products.edges into a plain Product[]. 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}
); } export function createCollectionEditor(opts: { collectionField: any; }): ComponentConfig { return { label: "Collection page", icon: , category: "commerce", defaultProps: { collection: null, showDescription: "no" }, fields: { collection: { label: "Collection", ...opts.collectionField }, showDescription: { label: "Description", type: "radio", options: [ { label: "Hide description", value: "no" }, { label: "Show description", value: "yes" }, ], }, }, render: (props) => , }; }