import { useState, useMemo, useEffect } from 'react'; import { useParams, useNavigate, Link } from 'react-router-dom'; import { useQuery } from '@tanstack/react-query'; import { motion } from 'framer-motion'; import { Clock, User, Music, Mic2, ChevronLeft, ChevronDown, ChevronUp } from 'lucide-react'; import { getTrack } from '../../../api/public/albums'; // 유튜브 URL에서 비디오 ID 추출 const getYoutubeVideoId = (url) => { if (!url) return null; const patterns = [ /(?:youtube\.com\/watch\?v=|youtu\.be\/|youtube\.com\/embed\/)([^&\n?#]+)/, ]; for (const pattern of patterns) { const match = url.match(pattern); if (match) return match[1]; } return null; }; // 쉼표 기준 줄바꿈 처리 const formatCredit = (text) => { if (!text) return null; return text.split(',').map((item, index) => ( {item.trim()} )); }; // 모바일 곡 상세 페이지 function TrackDetail() { const { name: albumName, trackTitle } = useParams(); const navigate = useNavigate(); // useQuery로 트랙 데이터 로드 const { data: track, isLoading: loading, error } = useQuery({ queryKey: ['track', albumName, trackTitle], queryFn: () => getTrack(albumName, trackTitle), enabled: !!albumName && !!trackTitle, }); const youtubeVideoId = useMemo(() => getYoutubeVideoId(track?.music_video_url), [track?.music_video_url]); // 가사 펼침 상태 const [showFullLyrics, setShowFullLyrics] = useState(false); // 전체화면 시 자동 가로 회전 처리 useEffect(() => { const handleFullscreenChange = async () => { const isFullscreen = !!document.fullscreenElement; if (isFullscreen) { // 전체화면 진입 시 가로 모드로 전환 시도 try { if (screen.orientation && screen.orientation.lock) { await screen.orientation.lock('landscape'); } } catch (e) { // 지원하지 않는 브라우저이거나 권한이 없는 경우 무시 console.log('Screen orientation lock not supported'); } } else { // 전체화면 종료 시 세로 모드로 복귀 try { if (screen.orientation && screen.orientation.unlock) { screen.orientation.unlock(); } } catch (e) { // 무시 } } }; document.addEventListener('fullscreenchange', handleFullscreenChange); document.addEventListener('webkitfullscreenchange', handleFullscreenChange); return () => { document.removeEventListener('fullscreenchange', handleFullscreenChange); document.removeEventListener('webkitfullscreenchange', handleFullscreenChange); }; }, []); if (loading) { return (
); } if (error || !track) { return (

트랙을 찾을 수 없습니다.

); } return ( {/* 트랙 정보 헤더 */}
{/* 앨범 커버 */} {track.album?.title} {/* 트랙 정보 */}
{track.is_title_track === 1 && ( TITLE )} Track {String(track.track_number).padStart(2, '0')}

{track.title}

{track.album?.album_type} · {track.album?.title}

{track.duration && (
{track.duration}
)}
{/* 뮤직비디오 섹션 */} {youtubeVideoId && (

뮤직비디오