import React, { memo, useCallback } from "react"; import { Album } from "../types"; import { PlayableCard } from "@/components/ui/PlayableCard"; import { EmptyState } from "@/components/ui/EmptyState"; import { GradientSpinner } from "@/components/ui/GradientSpinner"; import { Disc3, Trash2 } from "lucide-react"; import { api } from "@/lib/api"; interface AlbumsGridProps { albums: Album[]; onPlay: (albumId: string) => Promise; onDelete: (albumId: string, albumTitle: string) => void; isLoading?: boolean; } interface AlbumCardItemProps { album: Album; index: number; onPlay: (albumId: string) => Promise; onDelete: (albumId: string, albumTitle: string) => void; } const AlbumCardItem = memo( function AlbumCardItem({ album, index, onPlay, onDelete, }: AlbumCardItemProps) { const handlePlay = useCallback( () => onPlay(album.id), [album.id, onPlay] ); const handleDelete = useCallback( (e: React.MouseEvent) => { e.preventDefault(); e.stopPropagation(); onDelete(album.id, album.title); }, [album.id, album.title, onDelete] ); return (
} circular={false} onPlay={handlePlay} data-tv-card data-tv-card-index={index} tabIndex={0} /> {/* Delete button - only visible on hover */}
); }, (prevProps, nextProps) => { return prevProps.album.id === nextProps.album.id; } ); const AlbumsGrid = memo(function AlbumsGrid({ albums, onPlay, onDelete, isLoading = false, }: AlbumsGridProps) { if (isLoading) { return (
); } if (albums.length === 0) { return ( } title="No albums yet" description="Your library is empty. Sync your music to get started." /> ); } return (
{albums.map((album, index) => ( ))}
); }); export { AlbumsGrid };