import { motion, AnimatePresence } from 'framer-motion'; import { useState, useEffect, useCallback, useRef, useMemo } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { Play, Calendar, Music2, Clock, X, Download, ChevronDown, ChevronUp, FileText, ChevronRight } from 'lucide-react'; import { Swiper, SwiperSlide } from 'swiper/react'; import { Virtual } from 'swiper/modules'; import 'swiper/css'; import { getAlbumByName } from '../../../api/public/albums'; import { formatDate } from '../../../utils/date'; import LightboxIndicator from '../../../components/common/LightboxIndicator'; function MobileAlbumDetail() { const { name } = useParams(); const navigate = useNavigate(); const [lightbox, setLightbox] = useState({ open: false, images: [], index: 0, showNav: true }); const [showAllTracks, setShowAllTracks] = useState(false); const [showDescriptionModal, setShowDescriptionModal] = useState(false); const swiperRef = useRef(null); // useQuery로 앨범 데이터 로드 const { data: album, isLoading: loading } = useQuery({ queryKey: ['album', name], queryFn: () => getAlbumByName(name), enabled: !!name, }); // 라이트박스 열기 - 히스토리 추가 const openLightbox = useCallback((images, index, options = {}) => { setLightbox({ open: true, images, index, showNav: options.showNav !== false, teasers: options.teasers }); window.history.pushState({ lightbox: true }, ''); }, []); const closeLightbox = useCallback(() => { setLightbox(prev => ({ ...prev, open: false })); }, []); // 앨범 소개 열기 - 히스토리 추가 const openDescriptionModal = useCallback(() => { setShowDescriptionModal(true); window.history.pushState({ description: true }, ''); }, []); const closeDescriptionModal = useCallback(() => { setShowDescriptionModal(false); }, []); // 뒤로가기 처리 useEffect(() => { const handlePopState = () => { if (showDescriptionModal) { setShowDescriptionModal(false); } else if (lightbox.open) { setLightbox(prev => ({ ...prev, open: false })); } }; window.addEventListener('popstate', handlePopState); return () => window.removeEventListener('popstate', handlePopState); }, [showDescriptionModal, lightbox.open]); // 이미지 다운로드 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 || showDescriptionModal) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = ''; } return () => { document.body.style.overflow = ''; }; }, [lightbox.open, showDescriptionModal]); // 총 재생 시간 계산 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 (
앨범을 찾을 수 없습니다
티저 이미지
수록곡
{track.title}
{track.is_title_track === 1 && ( TITLE )}컨셉 포토
{album.description}