import { buildCoverArtUrl, coverArtCacheKey } from '../api/subsonicStreamUrl'; import type { SubsonicSong } from '../api/subsonicTypes'; import { songToTrack } from '../utils/songToTrack'; import React, { memo, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { Play, ListPlus, Star } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { usePlayerStore } from '../store/playerStore'; import CachedImage from './CachedImage'; import { enqueueAndPlay } from '../utils/playSong'; import { useDragDrop } from '../contexts/DragDropContext'; import { useOrbitSongRowBehavior } from '../hooks/useOrbitSongRowBehavior'; interface SongCardProps { song: SubsonicSong; disableArtwork?: boolean; artworkSize?: number; } function SongCard({ song, disableArtwork = false, artworkSize = 200 }: SongCardProps) { const { t } = useTranslation(); const navigate = useNavigate(); const openContextMenu = usePlayerStore(s => s.openContextMenu); const enqueue = usePlayerStore(s => s.enqueue); // buildCoverArtUrl emits a salted URL; memoize to avoid churn on rerenders. const coverUrl = useMemo( () => (song.coverArt ? buildCoverArtUrl(song.coverArt, artworkSize) : ''), [song.coverArt, artworkSize], ); const coverCacheKey = useMemo( () => (song.coverArt ? coverArtCacheKey(song.coverArt, artworkSize) : ''), [song.coverArt, artworkSize], ); const psyDrag = useDragDrop(); const { orbitActive, addTrackToOrbit } = useOrbitSongRowBehavior(); const handlePlay = () => { if (orbitActive) { addTrackToOrbit(song.id); return; } enqueueAndPlay(song); }; const handleEnqueue = () => { if (orbitActive) { addTrackToOrbit(song.id); return; } enqueue([songToTrack(song)]); }; const handleClick = handlePlay; const handleArtistClick = (e: React.MouseEvent) => { if (!song.artistId) return; e.stopPropagation(); navigate(`/artist/${song.artistId}`); }; return (
{song.title}
{song.artist}
{(song.userRating ?? 0) > 0 && (