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}