import { motion, AnimatePresence } from 'framer-motion'; import { useState, useEffect, useCallback } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { ArrowLeft, Play, Calendar, Music2, Clock, X, ChevronLeft, ChevronRight, Download } from 'lucide-react'; import { getAlbumByName } from '../../../api/public/albums'; import { formatDate } from '../../../utils/date'; // 모바일 앨범 상세 페이지 function MobileAlbumDetail() { const { name } = useParams(); const navigate = useNavigate(); const [album, setAlbum] = useState(null); const [loading, setLoading] = useState(true); const [lightbox, setLightbox] = useState({ open: false, images: [], index: 0 }); const [imageLoaded, setImageLoaded] = useState(false); // 라이트박스 네비게이션 const goToPrev = useCallback(() => { if (lightbox.images.length <= 1) return; setImageLoaded(false); setLightbox(prev => ({ ...prev, index: (prev.index - 1 + prev.images.length) % prev.images.length })); }, [lightbox.images.length]); const goToNext = useCallback(() => { if (lightbox.images.length <= 1) return; setImageLoaded(false); setLightbox(prev => ({ ...prev, index: (prev.index + 1) % prev.images.length })); }, [lightbox.images.length]); const closeLightbox = useCallback(() => { setLightbox(prev => ({ ...prev, open: false })); }, []); // 이미지 다운로드 const downloadImage = useCallback(async () => { const imageUrl = lightbox.images[lightbox.index]; if (!imageUrl) return; try { const response = await fetch(imageUrl); const blob = await response.blob(); const url = window.URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `fromis9_photo_${String(lightbox.index + 1).padStart(2, '0')}.webp`; document.body.appendChild(link); link.click(); document.body.removeChild(link); window.URL.revokeObjectURL(url); } catch (error) { console.error('다운로드 오류:', error); } }, [lightbox.images, lightbox.index]); // 라이트박스 body 스크롤 방지 useEffect(() => { if (lightbox.open) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = ''; } return () => { document.body.style.overflow = ''; }; }, [lightbox.open]); useEffect(() => { getAlbumByName(name) .then(data => { setAlbum(data); setLoading(false); }) .catch(error => { console.error('앨범 로드 오류:', error); setLoading(false); }); }, [name]); // 총 재생 시간 계산 const getTotalDuration = () => { if (!album?.tracks) return ''; let totalSeconds = 0; album.tracks.forEach(track => { if (track.duration) { const parts = track.duration.split(':'); totalSeconds += parseInt(parts[0]) * 60 + parseInt(parts[1]); } }); const mins = Math.floor(totalSeconds / 60); const secs = totalSeconds % 60; return `${mins}:${String(secs).padStart(2, '0')}`; }; if (loading) { return (
앨범을 찾을 수 없습니다
티저 포토
{album.description}