import { useQuery } from '@tanstack/react-query'; 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(); // useQuery로 앨범 데이터 로드 const { data: albums = [], isLoading: loading } = useQuery({ queryKey: ['albums'], queryFn: getAlbums, }); // 타이틀곡 찾기 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 (
); } return (
{/* 헤더 */}
앨범 프로미스나인의 음악을 만나보세요
{/* 통계 - 상단 배치 */}

{albumStats.정규}

정규 앨범

{albumStats.미니}

미니 앨범

{albumStats.싱글}

싱글 앨범

{albumStats.총}

총 앨범

{/* 앨범 그리드 */}
{albums.map((album, index) => ( handleAlbumClick(album.title)} > {/* 앨범 커버 */}
{album.title} {/* 호버 오버레이 */}

{album.tracks?.length || 0}곡 수록

{/* 앨범 정보 */}

{album.title}

{album.album_type_short || album.album_type}

{getTitleTrack(album.tracks)}

{formatDate(album.release_date, 'YYYY.MM.DD')}
))}
); } export default Album;