import { Link } from "wouter"; import { useQuery } from "@tanstack/react-query"; import Alert from "@mui/material/Alert"; import Button from "@mui/material/Button"; import Skeleton from "@mui/material/Skeleton"; import { Flame } from "lucide-react"; import { listProducts } from "@/lib/api"; import { usePlatform } from "@/lib/platform"; import { ApiNotice } from "./ApiNotice"; import "@/pages/products.css"; export function Catalog({ search = "", offset = 0, limit = 12, onNext, onPrevious, }: { search?: string; offset?: number; limit?: number; onNext?: () => void; onPrevious?: () => void; }) { const { organization } = usePlatform(); const query = useQuery({ queryKey: ["catalog", organization, search, offset, limit], queryFn: ({ signal }) => listProducts(organization, search, offset, limit, signal), enabled: Boolean(organization), retry: false, }); if (!organization) return ( Configure your organization on the{" "} Connection page {" "} to view the published collection. ); if (query.isPending) return (
{Array.from({ length: Math.min(limit, 4) }, (_, i) => ( ))}
); if (query.isError) return ( <> ); return ( <> {!query.data.length ? ( {search ? "No candles match your search. Try another name." : "No published candles are available yet."} ) : (
{query.data.map((product) => (
))}
)} {onNext && onPrevious && (
Page {offset / limit + 1}
)} ); }