import { useState, useEffect } from 'react'; interface GalleryThumbnailProps { id: string; columns: number; onSelect: (id: string, columns: number) => void; title: string; subscription: string; tags: string[]; nsfw: boolean; } const GalleryThumbnail = ({ id, columns, onSelect, title,nsfw, subscription, tags }: 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 [nsfwState, setNsfw] = useState(nsfw); const [subscriptionState, setSubscription] = useState(subscription); const [tagsState, setTags] = useState(tags); const openGallery = () => { onSelect(galleryId, galleryCollumns); }; const getData = async () => { setIsLoading(true); const thumbnailResponse = await fetch('/api/galleries/' + title + '/thumbnail'); const thumbnailUrl = await thumbnailResponse.text(); const imagesCountResponse = await fetch('/api/galleries/' + title + '/images/count'); const imageCount = await imagesCountResponse.json() as number; setImageCount(imageCount); setThumbnailUrl(thumbnailUrl); setIsLoading(false); }; useEffect(() => { getData(); }, [galleryId]); return (
{!isLoading ? ( <>

{title}

{imageCount} {nsfwState && ( NSFW )} {subscription === "Free" && ( Free )} {subscription === "Tier 1" && ( Tier 1 )} {subscription === "Tier 2" && ( Tier 2 )} {subscription === "Tier 3" && ( Tier 3 )}
{tagsState.map((tag, index) => ( {tag} ))}
) : (
)}
); }; export default GalleryThumbnail;