Files
minstrel/web/src/lib/components/QueueTrackRow.svelte
T
bvandeusenandClaude Opus 5.5 dae46ea980 refactor(web): every cover thumbnail goes through Cover, so a failed load falls back (DRY W2)
Seven places drew their own cover image. The Missing, Suspect sources,
Hidden and Reports rows showed a Music2 icon only when the track had no
album; a cover that failed to load (not fetched yet, or gone) showed a
broken image. The queue row, play bar and Now Playing each set the
placeholder in their own onerror, and the playlist card's images had no
fallback at all.

Cover gains fallback="track" (the Music2 icon a track row uses), and all
seven go through it, so each one handles a missing src and a failed load
the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 03:09:15 -05:00

106 lines
3.9 KiB
Svelte

<script lang="ts">
import { GripVertical, X } from 'lucide-svelte';
import type { TrackRef } from '#lib/api/types.js';
import { playFromQueueIndex, removeFromQueue, moveQueueItem } from '#lib/player/store.svelte.js';
import { coverUrl } from '#lib/media/covers.js';
import Cover from './Cover.svelte';
import { reorderDrag } from './reorder-drag';
import LikeButton from './LikeButton.svelte';
let { track, index, isCurrent } = $props<{
track: TrackRef;
index: number;
isCurrent: boolean;
}>();
function handleBodyClick() {
if (isCurrent) return;
playFromQueueIndex(index);
}
function handleRemove() {
removeFromQueue(index);
}
function handleHandleKeydown(e: KeyboardEvent) {
if (e.key === 'ArrowUp') {
e.preventDefault();
moveQueueItem(index, index - 1);
} else if (e.key === 'ArrowDown') {
e.preventDefault();
moveQueueItem(index, index + 1);
} else if (e.key === ' ' || e.key === 'Enter') {
// Reorder activates via arrow keys, not Space/Enter. Prevent
// default so Space doesn't scroll the queue list and Enter doesn't
// fire the button's no-op click.
e.preventDefault();
}
}
</script>
<div
use:reorderDrag={{ onMove: (delta) => moveQueueItem(index, index + delta) }}
class="flex items-center gap-2 border-b border-border px-3 py-2 h-16
[&.neodrag-dragging]:relative [&.neodrag-dragging]:z-10 [&.neodrag-dragging]:shadow-lg
{isCurrent ? 'border-l-2 border-l-accent bg-surface-hover' : 'bg-background'}"
>
<!--
The album art is the grab surface. The grip sits OVER the art rather than
in a column of its own, so it costs no horizontal space at all.
`use:reorderDrag` is on the row (above), so dragging works from anywhere —
the grip's real jobs are being the visual cue and the keyboard target, and
both survive here.
It stays VISIBLE at rest, just quiet — it is the only thing that says this
list can be reordered at all, so hiding it until hover would trade a
space problem for a discoverability one, and would
leave nothing for touch, which has no hover. The scrim only appears on
hover/focus so the artwork stays legible the rest of the time; the drop
shadow is what keeps the glyph readable over pale covers without one.
-->
<div class="relative h-10 w-10 shrink-0">
<div class="h-10 w-10 overflow-hidden rounded">
<Cover src={coverUrl(track.album_id)} />
</div>
<button
type="button"
aria-label="Reorder track (use arrow keys)"
aria-keyshortcuts="ArrowUp ArrowDown"
onkeydown={handleHandleKeydown}
class="group absolute inset-0 flex cursor-grab items-center justify-center rounded
text-white/70 transition hover:bg-black/45 hover:text-white
focus-visible:bg-black/45 focus-visible:text-white
focus-visible:outline-solid focus-visible:outline-2 focus-visible:outline-accent"
style="filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.9))"
>
<GripVertical size={16} />
</button>
</div>
<button
type="button"
onclick={handleBodyClick}
class="flex-1 text-left min-w-0 {isCurrent ? 'cursor-default' : 'cursor-pointer'}"
aria-label={isCurrent ? `Now playing — ${track.title}` : `Play ${track.title}`}
>
<div class="flex items-center gap-2 min-w-0">
{#if isCurrent}
<span class="text-xs text-accent-fg uppercase tracking-wide shrink-0">Now playing</span>
{/if}
<span class="font-medium truncate text-text-primary">{track.title}</span>
</div>
<div class="text-xs text-text-secondary truncate">{track.artist_name}</div>
</button>
<LikeButton entityType="track" entityId={track.id} />
<button
type="button"
onclick={handleRemove}
aria-label="Remove from queue"
class="text-text-secondary hover:text-text-primary shrink-0"
>
<X size={16} />
</button>
</div>