({
product,
index,
}: ProductListingProps)
| 14 | } |
| 15 | |
| 16 | const ProductListing = ({ |
| 17 | product, |
| 18 | index, |
| 19 | }: ProductListingProps) => { |
| 20 | const [isVisible, setIsVisible] = useState<boolean>(false) |
| 21 | |
| 22 | useEffect(() => { |
| 23 | const timer = setTimeout(() => { |
| 24 | setIsVisible(true) |
| 25 | }, index * 75) |
| 26 | |
| 27 | return () => clearTimeout(timer) |
| 28 | }, [index]) |
| 29 | |
| 30 | if (!product || !isVisible) return <ProductPlaceholder /> |
| 31 | |
| 32 | const label = PRODUCT_CATEGORIES.find( |
| 33 | ({ value }) => value === product.category |
| 34 | )?.label |
| 35 | |
| 36 | const validUrls = product.images |
| 37 | .map(({ image }) => |
| 38 | typeof image === 'string' ? image : image.url |
| 39 | ) |
| 40 | .filter(Boolean) as string[] |
| 41 | |
| 42 | if (isVisible && product) { |
| 43 | return ( |
| 44 | <Link |
| 45 | className={cn( |
| 46 | 'invisible h-full w-full cursor-pointer group/main', |
| 47 | { |
| 48 | 'visible animate-in fade-in-5': isVisible, |
| 49 | } |
| 50 | )} |
| 51 | href={`/product/${product.id}`}> |
| 52 | <div className='flex flex-col w-full'> |
| 53 | <ImageSlider urls={validUrls} /> |
| 54 | |
| 55 | <h3 className='mt-4 font-medium text-sm text-gray-700'> |
| 56 | {product.name} |
| 57 | </h3> |
| 58 | <p className='mt-1 text-sm text-gray-500'> |
| 59 | {label} |
| 60 | </p> |
| 61 | <p className='mt-1 font-medium text-sm text-gray-900'> |
| 62 | {formatPrice(product.price)} |
| 63 | </p> |
| 64 | </div> |
| 65 | </Link> |
| 66 | ) |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | const ProductPlaceholder = () => { |
| 71 | return ( |
nothing calls this directly
no test coverage detected