import { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { ArrowLeft, X, ChevronLeft, ChevronRight } from 'lucide-react'; import { motion, AnimatePresence } from 'framer-motion'; // 모바일 앨범 갤러리 페이지 function MobileAlbumGallery() { const { name } = useParams(); const navigate = useNavigate(); const [album, setAlbum] = useState(null); const [photos, setPhotos] = useState([]); const [loading, setLoading] = useState(true); const [selectedIndex, setSelectedIndex] = useState(null); useEffect(() => { fetch('/api/albums') .then(res => res.json()) .then(data => { const found = data.find(a => a.folder_name === name); if (found) { setAlbum(found); fetch(`/api/albums/${found.id}/photos`) .then(res => res.json()) .then(setPhotos) .catch(console.error); } setLoading(false); }) .catch(console.error); }, [name]); // 이미지 네비게이션 const goToImage = (delta) => { const newIndex = selectedIndex + delta; if (newIndex >= 0 && newIndex < photos.length) { setSelectedIndex(newIndex); } }; if (loading) { return (
); } return (
{/* 헤더 */}
{album?.title} 갤러리
{/* 갤러리 그리드 */}
{photos.map((photo, index) => ( setSelectedIndex(index)} className="aspect-square bg-gray-200 cursor-pointer" > ))}
{/* 풀스크린 뷰어 */} {selectedIndex !== null && ( {/* 뷰어 헤더 */}
{selectedIndex + 1} / {photos.length}
{/* 이미지 */}
{/* 좌우 네비게이션 */} {selectedIndex > 0 && ( )} {selectedIndex < photos.length - 1 && ( )}
)}
); } export default MobileAlbumGallery;