import { useEffect, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import axiosInstance from "../api/axiosInstance"; import { useAuth } from "../context/authContext"; import type { CatalogItem } from "../utils/types"; const MySongs = () => { const { user } = useAuth(); const navigate = useNavigate(); const [artistCatalog, setArtistCatalog] = useState([]); const [loading, setLoading] = useState(true); const [activeTab, setActiveTab] = useState<"singles" | "albums">("singles"); useEffect(() => { const fetchArtistCatalog = async () => { try { setLoading(true); const response = await axiosInstance.get("/songs/catalog"); const data = response.data; setArtistCatalog(data); } catch (error) { console.error("Error fetching music:", error); } finally { setLoading(false); } }; if (user?.isArtist) { fetchArtistCatalog(); } }, [user]); if (!user?.isArtist) { return (

You need to be an artist to access this page.

← Back to Home
); } if (loading) { return (

Loading your music…

); } return (
{/* Header */}

My Music

Manage your songs and albums

{/* Tabs */}
{/* Content */} {activeTab === "singles" ? (
{artistCatalog.filter((item) => item.type === "SONG").length === 0 ? (

You haven't published any singles yet

) : ( artistCatalog .filter((item) => item.type === "SONG") .map((song, index) => (
{index + 1} {song.title} { (e.target as HTMLImageElement).src = "/favicon.png"; }} />
{song.title}

{song.genre}

{song.releaseDate}

)) )}
) : (
{artistCatalog.filter((item) => item.type === "ALBUM").length === 0 ? (

You haven't published any albums yet

) : ( artistCatalog .filter((item) => item.type === "ALBUM") .map((album) => (
{album.title} { (e.target as HTMLImageElement).src = "/favicon.png"; }} />

{album.title}

{album.genre}

{album.releaseDate}

)) )}
)}
); }; export default MySongs;