import { useState, useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { motion } from 'framer-motion'; import { Calendar, Music } from 'lucide-react'; import { getAlbums } from '../../../api/public/albums'; import { formatDate } from '../../../utils/date'; function Album() { const navigate = useNavigate(); const [albums, setAlbums] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { getAlbums() .then(data => { setAlbums(data); setLoading(false); }) .catch(error => { console.error('앨범 데이터 로드 오류:', error); setLoading(false); }); }, []); // 타이틀곡 찾기 const getTitleTrack = (tracks) => { if (!tracks || tracks.length === 0) return ''; const titleTrack = tracks.find(t => t.is_title_track); return titleTrack ? titleTrack.title : tracks[0].title; }; // 앨범 타입별 개수 계산 (album_type_short 우선 사용) const getAlbumType = (album) => album.album_type_short || album.album_type; const albumStats = { 정규: albums.filter(a => getAlbumType(a) === '정규').length, 미니: albums.filter(a => getAlbumType(a) === '미니').length, 싱글: albums.filter(a => getAlbumType(a) === '싱글').length, 총: albums.length }; // 앨범 클릭 핸들러 const handleAlbumClick = (albumTitle) => { navigate(`/album/${encodeURIComponent(albumTitle)}`); }; if (loading) { return (
{albumStats.정규}
정규 앨범
{albumStats.미니}
미니 앨범
{albumStats.싱글}
싱글 앨범
{albumStats.총}
총 앨범
{album.tracks?.length || 0}곡 수록
{getTitleTrack(album.tracks)}