From e200dfd3ebefa91350691113824c1c6e6e7d9d79 Mon Sep 17 00:00:00 2001
From: vicrodh <103399283+vicrodh@users.noreply.github.com>
Date: Fri, 23 Jan 2026 10:53:40 -0600
Subject: [PATCH] =?UTF-8?q?fix(queue):=20show=20actual=20remaining=20track?=
=?UTF-8?q?s=20and=20=E2=88=9E=20when=20infinite=20play=20active?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/lib/components/QueuePanel.svelte | 8 +++----
src/routes/+page.svelte | 34 ++++++++++++++++++----------
2 files changed, 25 insertions(+), 17 deletions(-)
diff --git a/src/lib/components/QueuePanel.svelte b/src/lib/components/QueuePanel.svelte
index 1d7e4d07e..883c21413 100644
--- a/src/lib/components/QueuePanel.svelte
+++ b/src/lib/components/QueuePanel.svelte
@@ -145,11 +145,9 @@
.slice(0, displayCount);
});
- // The real remaining count is queueTotalTracks minus current track (if playing)
- // queueTotalTracks from backend includes all tracks in queue
- const realRemainingTracks = $derived(currentTrack ? Math.max(0, queueTotalTracks - 1) : queueTotalTracks);
+ // queueTotalTracks now represents the actual remaining tracks from backend
const displayedTracks = $derived(Math.min(filteredTracks.length, displayCount));
- const hasMoreTracks = $derived(!searchQuery && (upcomingTracks.length > displayCount || realRemainingTracks > upcomingTracks.length));
+ const hasMoreTracks = $derived(!searchQuery && (upcomingTracks.length > displayCount || queueTotalTracks > upcomingTracks.length));
const canDrag = $derived(!searchQuery.trim());
function loadMore() {
@@ -282,7 +280,7 @@
{#if upcomingTracks.length > 0}
- {$t('player.upNext').toUpperCase()} ({displayedTracks} {$t('player.ofTotal')} {realRemainingTracks})
+ {$t('player.upNext').toUpperCase()} ({displayedTracks} {$t('player.ofTotal')} {infinitePlayEnabled ? '∞' : queueTotalTracks})
{#each filteredTracks as track, index}
diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte
index 3702dd3c1..c042b86db 100644
--- a/src/routes/+page.svelte
+++ b/src/routes/+page.svelte
@@ -331,6 +331,7 @@
let repeatMode = $state('off');
let queue = $state([]);
let queueTotalTracks = $state(0);
+ let queueRemainingTracks = $state(0); // Actual remaining tracks (total - current_index - 1)
let historyTracks = $state([]);
let infinitePlayEnabled = $state(false);
@@ -2126,21 +2127,30 @@
};
});
- // Sync queue state when opening queue panel (including history)
+ // Sync queue state when opening queue panel (including history and remaining count)
$effect(() => {
if (isQueueOpen) {
syncQueueState();
- // Also fetch history from backend
+ // Also fetch history and calculate remaining tracks from backend
getBackendQueueState().then((state) => {
- 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
- }));
+ 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
+ }));
+ }
}
});
}
@@ -2522,7 +2532,7 @@
onClose={closeQueue}
currentTrack={currentQueueTrack ?? undefined}
upcomingTracks={queue}
- {queueTotalTracks}
+ queueTotalTracks={queueRemainingTracks}
{historyTracks}
onPlayTrack={handleQueueTrackPlay}
onPlayHistoryTrack={handlePlayHistoryTrack}