0eaaf66748
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>
23 lines
771 B
TypeScript
23 lines
771 B
TypeScript
// Converts a PlaylistTrack row into the minimal TrackRef shape used
|
|
// by play queues + track menus. Centralizes the mapping so server
|
|
// additions (new TrackRef fields) only update one site.
|
|
//
|
|
// Returns null when the upstream track has been removed (track_id
|
|
// is null on the playlist row); callers should filter nulls.
|
|
|
|
import type { PlaylistTrack, TrackRef } from '$lib/api/types';
|
|
|
|
export function playlistTrackToRef(row: PlaylistTrack): TrackRef | null {
|
|
if (!row.track_id) return null;
|
|
return {
|
|
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 ?? ''
|
|
};
|
|
}
|