import { useNavigate } from "react-router-dom"; import { useState } from "react"; import { Music, Disc3, Play, Plus } from "lucide-react"; import type { ArtistContribution } from "../../utils/types"; import axiosInstance from "../../api/axiosInstance"; interface ArtistViewProps { contributions: ArtistContribution[]; } const ArtistView = ({ contributions }: ArtistViewProps) => { const navigate = useNavigate(); const [items, setItems] = useState(contributions); const [toast, setToast] = useState<{ message: string; show: boolean }>({ message: "", show: false, }); 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-100 text-purple-700", PERFORMER: "bg-blue-100 text-blue-700", PRODUCER: "bg-green-100 text-green-700", MAIN_VOCAL: "bg-pink-100 text-pink-700", }; return colors[role] || "bg-gray-100 text-gray-700"; }; const showToast = (message: string) => { setToast({ message, show: true }); setTimeout(() => { setToast({ message: "", show: false }); }, 2000); }; 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, ), ); showToast( data.isLiked ? `Liked "${title}"` : `Removed ${title} from likes`, ); } catch (err: any) { showToast(err.response?.data?.error); } }; return (
{toast.show && (
{toast.message}
)} {albums.length > 0 && (

Albums

{albums.map((album) => (
navigate(`/collection/album/${album.id}`)} >
{album.role.replace("_", " ")}

{album.title}

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

Songs

{songs.map((song) => (
navigate(`/musical-entity/${song.id}`)} >

{song.title}

{song.genre}
{song.role.replace("_", " ")}
))}
)} {contributions.length === 0 && (

No contributions yet

Start creating music to see it here

)}
); }; export default ArtistView;