Files
minstrel/web/src/lib/components/PlaylistTrackRow.svelte
T
bvandeusenandClaude Opus 5.5 10d50dccbd docs: web comments say what the app does, not how it came to be (#6277)
Rewrites the web app's comments to rule 32. Task, milestone, rule and
spec ids are gone; regression stories are restated as the trap they
guard (public auth routes, the menu's stopPropagation, universal loads
under adapter-static, metric deltas with their margin). Flutter and
Tauri mentions now name the Android app or a native shell, operator
quotes and dates are dropped, and one library's counts no longer
appear outside test fixtures. Verified with a TypeScript-scanner token
comparison (template literals and regex literals re-scanned): only
comment text changed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 12:42:12 -04:00

117 lines
3.8 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
// A track in a playlist. The look is TrackListRow's; what this adds is
// the reorder grip, remove, and the two ways an entry can be dead.
import { GripVertical, X } from 'lucide-svelte';
import type { PlaylistTrack } from '#lib/api/types.js';
import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js';
import TrackListRow from './TrackListRow.svelte';
let {
row,
isOwner,
onRemove,
onPlay,
onMove
}: {
row: PlaylistTrack;
isOwner: boolean;
onRemove: (position: number) => void;
onPlay: (position: number) => void;
onMove?: (fromPos: number, toPos: number) => void;
} = $props();
// Two different ways a row can be dead, with the same behaviour and
// deliberately different copy. A removed track is gone for good; a
// missing file is a track we still have — history, likes and all —
// whose bytes aren't on disk right now. Telling the user
// "file missing" invites them to fix it; a strikethrough would say
// "deleted", which is a lie about a file that may well come back.
const isMissingFile = $derived(row.unavailable);
const isRemoved = $derived(row.track_id === null);
const isUnavailable = $derived(isRemoved || isMissingFile);
// null when the entry cannot be played, which hides like, radio, add
// and the menu.
const liveTrack = $derived(playlistTrackToRef(row));
const canDrag = $derived(isOwner && !isUnavailable);
const drag = $derived(
isOwner
? {
disabled: !canDrag,
handle: '[data-reorder-handle]',
onMove: (delta: number) => onMove?.(row.position, row.position + delta)
}
: null
);
function handleHandleKeydown(e: KeyboardEvent) {
if (e.key === 'ArrowUp') {
e.preventDefault();
onMove?.(row.position, row.position - 1);
} else if (e.key === 'ArrowDown') {
e.preventDefault();
onMove?.(row.position, row.position + 1);
} else if (e.key === ' ' || e.key === 'Enter') {
// Reorder activates via arrow keys, not Space/Enter. Prevent
// default so Space doesn't scroll the list and Enter doesn't
// fire the button's no-op click.
e.preventDefault();
}
}
</script>
<TrackListRow
title={row.title}
subtitle={`${row.artist_name} · ${row.album_title}`}
durationSec={row.duration_sec}
track={liveTrack}
ariaLabel={`Play ${row.title}`}
rowTitle={isMissingFile
? 'This track’s file is missing from the library, so it can’t be played. It stays in the playlist, and returns automatically if the file comes back.'
: undefined}
disabled={isUnavailable}
struck={isRemoved}
{drag}
onActivate={() => onPlay(row.position)}
>
{#snippet lead()}
{#if isOwner}
<button
type="button"
data-reorder-handle
disabled={!canDrag}
aria-label="Reorder track (drag or use arrow keys)"
aria-keyshortcuts="ArrowUp ArrowDown"
onclick={(e) => e.stopPropagation()}
onkeydown={handleHandleKeydown}
class="cursor-grab p-1 text-text-muted hover:text-text-primary
active:cursor-grabbing focus-visible:outline-solid focus-visible:outline-2
focus-visible:outline-accent disabled:cursor-not-allowed disabled:opacity-50"
>
<GripVertical size={16} strokeWidth={1} />
</button>
{/if}
{/snippet}
{#snippet note()}
{#if isMissingFile}
<span class="text-error-fg"> · File missing</span>
{/if}
{/snippet}
{#snippet trailing()}
{#if isOwner}
<button
type="button"
onclick={(e) => { e.stopPropagation(); onRemove(row.position); }}
aria-label={`Remove ${row.title} from playlist`}
class="shrink-0 rounded p-1 text-text-muted hover:bg-surface hover:text-action-destructive"
>
<X size={16} strokeWidth={1} />
</button>
{/if}
{/snippet}
</TrackListRow>