import { useEffect, useState } from "react"; import { Link } from "react-router"; import { shopifyFetch } from "@/editor/services/shopify/client"; import { GET_COLLECTIONS_QUERY } from "@/editor/graphql/collections"; import { Typography } from "@/editor/theme/Typography"; export type CollectionGridProps = { tagline: string; heading: string; subheading: string; layout: "tiles" | "editorial"; limit: number; }; type CollectionRow = { id: string; handle: string; title: string; description?: string; image?: { url: string; altText?: string }; }; export function CollectionGrid({ tagline, heading, subheading, layout, limit, }: CollectionGridProps) { const [collections, setCollections] = useState([]); useEffect(() => { shopifyFetch({ query: GET_COLLECTIONS_QUERY, variables: { first: limit }, }) .then((res) => { const list = (res.data?.collections?.edges ?? []).map((e: any) => e.node); setCollections(list); }) .catch(() => setCollections([])); }, [limit]); const isEditorial = layout === "editorial"; return (
{tagline ? (

{tagline}

) : null} {heading} {subheading ? ( {subheading} ) : null}
{(collections.length === 0 ? Array.from({ length: limit }).map((_, i) => ({ id: `sk-${i}` }) as any) : collections ).map((c: CollectionRow) => (
{c.image?.url ? ( {c.image.altText ) : null} {isEditorial ? (
{c.title} Shop now →
) : null}
{!isEditorial ? (

{c.title}

) : null} ))}
); }