feat(web): add enqueueTrack, enqueueTracks, playRadio to player store

enqueueTrack/enqueueTracks append to the queue without disturbing
playback state (no auto-play on append, no state mutation when queue
was non-empty). playRadio fetches /api/radio?seed_track=<id> and
feeds the response into playQueue. Empty response leaves queue alone.
This commit is contained in:
2026-04-25 15:22:03 -04:00
parent 8e80b6e0de
commit 7dd77a4723
2 changed files with 74 additions and 1 deletions
+20 -1
View File
@@ -1,4 +1,5 @@
import type { TrackRef } from '$lib/api/types';
import type { TrackRef, RadioResponse } from '$lib/api/types';
import { api } from '$lib/api/client';
export type PlayerState = 'idle' | 'loading' | 'playing' | 'paused' | 'error';
export type RepeatMode = 'off' | 'all' | 'one';
@@ -196,3 +197,21 @@ export function reportStateFromAudio(
return;
}
}
export function enqueueTrack(t: TrackRef): void {
_queue = [..._queue, t];
if (_state === 'idle') _index = 0;
}
export function enqueueTracks(ts: TrackRef[]): void {
if (ts.length === 0) return;
_queue = [..._queue, ...ts];
if (_state === 'idle') _index = 0;
}
export async function playRadio(seedTrackId: string): Promise<void> {
const resp = await api.get<RadioResponse>(
`/api/radio?seed_track=${encodeURIComponent(seedTrackId)}`
);
if (resp.tracks.length > 0) playQueue(resp.tracks, 0);
}