import React, { memo, useCallback } from "react"; import { Music, Trash2 } from "lucide-react"; import { Artist } from "../types"; import { PlayableCard } from "@/components/ui/PlayableCard"; import { EmptyState } from "@/components/ui/EmptyState"; import { GradientSpinner } from "@/components/ui/GradientSpinner"; import { api } from "@/lib/api"; interface ArtistsGridProps { artists: Artist[]; onPlay: (artistId: string) => Promise; onDelete: (artistId: string, artistName: string) => void; isLoading?: boolean; } const getArtistImageSrc = (coverArt?: string): string | null => { if (!coverArt) return null; return api.getCoverArtUrl(coverArt, 300); }; interface ArtistCardItemProps { artist: Artist; index: number; onPlay: (artistId: string) => Promise; onDelete: (artistId: string, artistName: string) => void; } const ArtistCardItem = memo( function ArtistCardItem({ artist, index, onPlay, onDelete, }: ArtistCardItemProps) { const handlePlay = useCallback( () => onPlay(artist.id), [artist.id, onPlay] ); const handleDelete = useCallback( (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); onDelete(artist.id, artist.name); }, [artist.id, artist.name, onDelete] ); return (
} circular={true} onPlay={handlePlay} data-tv-card data-tv-card-index={index} tabIndex={0} /> {/* Delete button - only visible on hover */}
); }, (prevProps, nextProps) => { return prevProps.artist.id === nextProps.artist.id; } ); const ArtistsGrid = memo(function ArtistsGrid({ artists, onPlay, onDelete, isLoading = false, }: ArtistsGridProps) { if (isLoading) { return (
); } if (artists.length === 0) { return ( } title="No artists yet" description="Your library is empty. Sync your music to get started." /> ); } return (
{artists.map((artist, index) => ( ))}
); }); export { ArtistsGrid };