import {useState} from 'react' import {ChevronRight} from 'lucide-react' import Button from '@/components/button' import {HOME_CATEGORY_META_MAP} from '@/constant' import type {ProductCategory, ProductItem} from '@/types' type GoodsCategoryListProps = { categories: ProductCategory[] loading?: boolean emptyText?: string showMore?: boolean onMoreClick?: (categoryId: ProductCategory['id']) => void onRedeem: (product: ProductItem, categoryId: ProductCategory['id']) => void } function GoodsImage({ imageUrl, }: { imageUrl?: string }) { const [hasError, setHasError] = useState(false) const showFallback = !imageUrl || hasError return (
{showFallback ? (
NO IMAGE
) : null} {imageUrl ? ( setHasError(true)} /> ) : null}
) } export function GoodsCategoryList({ categories, loading = false, emptyText = 'No goods available yet.', showMore = false, onMoreClick, onRedeem, }: GoodsCategoryListProps) { if (loading) { return (
Loading ...
) } if (!categories.length) { return (
{emptyText}
) } return (
{categories.map((category) => { const CategoryIcon = HOME_CATEGORY_META_MAP[category.id].icon return (
{category.name}
{showMore && onMoreClick ? ( ) : null}
{category.items.map((product) => (
{product.title}
{product.subtitle}
{product.score}
))}
) })}
) }