import { useEffect, useState } from "react"; import { useNavigate, useParams } from "react-router-dom"; import axiosInstance from "../api/axiosInstance"; interface Song { id: number; title: string; genre: string; type: "SONG"; releasedBy: string; isLikedByCurrentUser?: boolean; } interface MusicalEntity { id: number; title: string; genre: string; type: string; releasedBy: string; isLikedByCurrentUser?: boolean; songs?: Song[]; } const MusicalCollection = () => { const { type, id } = useParams(); const navigate = useNavigate(); const [collection, setCollection] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { const fetchData = async () => { setIsLoading(true); setError(null); try { const endpoint = type === "album" ? `/albums/${id}` : `/playlists/${id}`; const response = await axiosInstance.get(endpoint); console.log(response.data); setCollection(response.data); } catch (err: any) { setError(err.response?.data?.error || "Failed to load collection"); } finally { setIsLoading(false); } }; fetchData(); }, [id, type]); if (isLoading) { return
Loading...
; } if (error) { return (

Error

{error}

); } if (!collection) return null; return (
{collection.title.charAt(0).toUpperCase()}
{collection.type}

{collection.title}

{collection.releasedBy} {collection.genre} {collection.songs && ( <> {collection.songs.length} song {collection.songs.length !== 1 ? "s" : ""} )}

Songs

{collection.songs && collection.songs.length > 0 ? (
{collection.songs.map((song, index) => (
{index + 1}

{song.title}

{song.releasedBy}

{song.genre}
))}
) : (

No songs available

)}
); }; export default MusicalCollection;