import { Disc3, Music } from "lucide-react"; import { useState } from "react"; import { useNavigate } from "react-router-dom"; import { toast } from "react-toastify"; import axiosInstance, { baseURL } from "../../api/axiosInstance"; import type { ArtistContribution } from "../../utils/types"; import SongItem from "../SongItem"; interface ArtistViewProps { contributions: ArtistContribution[]; } const ArtistView = ({ contributions }: ArtistViewProps) => { const navigate = useNavigate(); const [items, setItems] = useState(contributions); const [openDropdownSongId, setOpenDropdownSongId] = useState( null, ); const albums = items.filter((c) => c.entityType === "ALBUM"); const songs = items.filter((c) => c.entityType === "SONG"); const getRoleColor = (role: string) => { const colors: { [key: string]: string } = { COMPOSER: "bg-purple-500/20 text-purple-300", PERFORMER: "bg-blue-500/20 text-blue-300", PRODUCER: "bg-green-500/20 text-green-300", MAIN_VOCAL: "bg-pink-500/20 text-pink-300", }; return colors[role] || "bg-white/10 text-gray-300"; }; const handleLike = async (id: number, title: string) => { try { const response = await axiosInstance.post(`/musical-entity/${id}/like`); const data = response.data; setItems((prevItems) => prevItems.map((item) => item.id === data.entityId ? { ...item, isLikedByCurrentUser: data.isLiked } : item, ), ); toast.success( data.isLiked ? `Liked "${title}"` : `Removed "${title}" from likes`, ); } catch (err: any) { toast.error(err.response?.data?.error || "Failed to like the item"); } }; return (
{albums.length > 0 && (

Albums

{albums.map((album) => (
navigate(`/collection/album/${album.id}`)} >
{album.title} { (e.target as HTMLImageElement).src = "/favicon.png"; }} />
{album.role.replace("_", " ")}

{album.title}

))}
)} {songs.length > 0 && (

Songs

{songs.map((song) => ( handleLike(song.id, song.title)} isDropdownOpen={openDropdownSongId === song.id} onDropdownToggle={setOpenDropdownSongId} /> ))}
)} {contributions.length === 0 && (

No contributions yet

Start creating music to see it here

)}
); }; export default ArtistView;