2024-05-26 03:46:00 -04:00
|
|
|
import { useState, useEffect } from 'react';
|
2024-05-26 02:14:59 -04:00
|
|
|
|
|
|
|
interface GalleryThumbnailProps {
|
2024-05-26 13:08:59 -04:00
|
|
|
id: string;
|
|
|
|
onSelect: (id:string) => void;
|
2024-05-26 02:14:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
const GalleryThumbnail = ({ id, onSelect }: GalleryThumbnailProps) => {
|
2024-05-26 13:08:59 -04:00
|
|
|
const [galleryId, setGalleryId] = useState<string>(id);
|
|
|
|
const [thumbnailUrl, setThumbnailUrl] = useState<string>('');
|
|
|
|
const [isLoading, setIsLoading] = useState<boolean>(true);
|
|
|
|
|
|
|
|
const openGallery = () => {
|
2024-05-26 02:14:59 -04:00
|
|
|
onSelect(galleryId);
|
|
|
|
};
|
|
|
|
|
|
|
|
const getData = async () => {
|
2024-05-26 03:46:00 -04:00
|
|
|
setIsLoading(true);
|
2024-05-26 02:14:59 -04:00
|
|
|
const thumbnailResponse = await fetch('/api/galleries/'+galleryId+'/thumbnail');
|
|
|
|
const thumbnailUrl = await thumbnailResponse.text();
|
|
|
|
setThumbnailUrl(thumbnailUrl);
|
2024-05-26 03:46:00 -04:00
|
|
|
setIsLoading(false);
|
2024-05-26 02:14:59 -04:00
|
|
|
}
|
2024-05-26 03:46:00 -04:00
|
|
|
|
2024-05-26 02:14:59 -04:00
|
|
|
useEffect(() => {
|
|
|
|
getData();
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
2024-05-26 03:46:00 -04:00
|
|
|
<div className="py-3 sm:max-w-xl sm:mx-auto flex-3">
|
|
|
|
<div className="h-48 overflow-visible w-full relative hover:scale-105 shadow-lg bg-gray-400 rounded-3xl">
|
|
|
|
{!isLoading && <img
|
2024-05-26 02:14:59 -04:00
|
|
|
className={`aspect-content rounded-3xl`}
|
|
|
|
src={thumbnailUrl}
|
|
|
|
alt=""
|
2024-05-26 13:08:59 -04:00
|
|
|
onClick={openGallery}
|
2024-05-26 02:14:59 -04:00
|
|
|
style={{ width: '20rem', height: '20rem', objectFit: 'cover' }}
|
2024-05-26 03:46:00 -04:00
|
|
|
/>}
|
2024-05-26 02:14:59 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default GalleryThumbnail;
|