refactor(web): playlistTrackToRef helper to dedupe TrackRef
reconstruction (#375) PlaylistTrackRow.svelte and PlaylistCard.toTrackRefs both rebuilt TrackRef from PlaylistTrack with the same field-by-field literal. Server adding a new TrackRef field would have needed both sites updated; now one helper owns the mapping. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
import { draggable, type DragEventData } from '@neodrag/svelte';
|
||||
import LikeButton from './LikeButton.svelte';
|
||||
import TrackMenu from './TrackMenu.svelte';
|
||||
import type { PlaylistTrack, TrackRef } from '$lib/api/types';
|
||||
import type { PlaylistTrack } from '$lib/api/types';
|
||||
import { playlistTrackToRef } from '$lib/playlists/playlistTrackToRef';
|
||||
import { offsetToDelta } from './queue-row-math';
|
||||
|
||||
let {
|
||||
@@ -22,22 +23,9 @@
|
||||
|
||||
const isUnavailable = $derived(row.track_id === null);
|
||||
|
||||
// Construct a minimal TrackRef for the kebab menu when the upstream
|
||||
// track still exists. When unavailable, the menu is hidden.
|
||||
const liveTrack = $derived<TrackRef | null>(
|
||||
row.track_id
|
||||
? ({
|
||||
id: row.track_id,
|
||||
title: row.title,
|
||||
album_id: row.album_id ?? '',
|
||||
album_title: row.album_title,
|
||||
artist_id: row.artist_id ?? '',
|
||||
artist_name: row.artist_name,
|
||||
duration_sec: row.duration_sec,
|
||||
stream_url: row.stream_url ?? ''
|
||||
} as TrackRef)
|
||||
: null
|
||||
);
|
||||
// Reconstruct a minimal TrackRef for the kebab menu when the
|
||||
// upstream track still exists. When unavailable, the menu is hidden.
|
||||
const liveTrack = $derived(playlistTrackToRef(row));
|
||||
|
||||
let measuredRowHeight = 56; // sensible default; replaced on dragStart
|
||||
|
||||
|
||||
Reference in New Issue
Block a user