From 1f614c57502fb11f4d585a8bca3cef66f489ca06 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 23 Jan 2026 11:14:13 -0600 Subject: [PATCH] fix(queue): update remaining count in real-time when tracks advance --- src/routes/+page.svelte | 56 +++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ecbf99722..5a0618f16 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2131,31 +2131,43 @@ $effect(() => { if (isQueueOpen) { syncQueueState(); - // Also fetch history and calculate remaining tracks from backend - getBackendQueueState().then((state) => { - if (state) { - // Calculate remaining tracks: total - current_index - 1 (for current track) - if (state.current_index !== null && state.total_tracks > 0) { - queueRemainingTracks = state.total_tracks - state.current_index - 1; - } else { - queueRemainingTracks = state.total_tracks; - } - - if (state.history) { - historyTracks = state.history.map(t => ({ - id: String(t.id), - artwork: t.artwork_url || '', - title: t.title, - artist: t.artist, - duration: formatDuration(t.duration_secs), - trackId: t.id - })); - } - } - }); + updateQueueCounts(); } }); + // Update remaining count when track changes while queue is open + $effect(() => { + // Track the currentTrack to trigger on change + const trackId = currentTrack?.id; + if (isQueueOpen && trackId !== undefined) { + updateQueueCounts(); + } + }); + + // Helper function to fetch and update queue counts and history + async function updateQueueCounts() { + const state = await getBackendQueueState(); + if (state) { + // Calculate remaining tracks: total - current_index - 1 (for current track) + if (state.current_index !== null && state.total_tracks > 0) { + queueRemainingTracks = state.total_tracks - state.current_index - 1; + } else { + queueRemainingTracks = state.total_tracks; + } + + if (state.history) { + historyTracks = state.history.map(t => ({ + id: String(t.id), + artwork: t.artwork_url || '', + title: t.title, + artist: t.artist, + duration: formatDuration(t.duration_secs), + trackId: t.id + })); + } + } + } + // Start/stop lyrics active line updates based on playback state and visibility $effect(() => { const lyricsVisible = lyricsSidebarVisible || isFocusModeOpen || isFullScreenOpen;