import { useState, useEffect } from 'react'; interface GalleryThumbnailProps { id: string; columns: number; onSelect: (id: string, columns: number) => void; title: string; subscription: string; } const GalleryThumbnail = ({ id, columns, onSelect, title, subscription }: GalleryThumbnailProps) => { const [galleryId, setGalleryId] = useState(id); const [thumbnailUrl, setThumbnailUrl] = useState(''); const [isLoading, setIsLoading] = useState(true); const [galleryCollumns, setColumns] = useState(columns); const [imageCount, setImageCount] = useState(0); const openGallery = () => { onSelect(galleryId, galleryCollumns); }; const getData = async () => { setIsLoading(true); const thumbnailResponse = await fetch('/api/galleries/' + galleryId + '/thumbnail'); const thumbnailUrl = await thumbnailResponse.text(); const imagesCountResponse = await fetch('/api/galleries/' + galleryId + '/images/count'); const imageCount = await imagesCountResponse.json() as number; setImageCount(imageCount); setThumbnailUrl(thumbnailUrl); setIsLoading(false); }; useEffect(() => { getData(); }, [galleryId]); return (
{!isLoading && ( <>

{title}

{imageCount} pictures in this gallery.
{imageCount}
{imageCount} pictures in this gallery.
{subscription === "Free" && (
Free
This is free for everyone.
)} {subscription === "Tier 1" && (
Tier 1
This requires a Tier 1 subscription.
)} {subscription === "Tier 2" && (
Tier 2
This requires a Tier 2 subscription.
)} {subscription === "Tier 3" && (
Tier 3
This requires a Tier 3 subscription.
)}
)}
); }; export default GalleryThumbnail;