fix(queue): update remaining count in real-time when tracks advance

This commit is contained in:
vicrodh committed 2026-01-23 11:14:13 -06:00
1 parent 9501a4b909
commit 1f614c5750
1 file changed
+34 -22
+34 -22
View File
@@ -2131,31 +2131,43 @@
$effect(() => { $effect(() => {
if (isQueueOpen) { if (isQueueOpen) {
syncQueueState(); syncQueueState();
// Also fetch history and calculate remaining tracks from backend updateQueueCounts();
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
}));
}
}
});
} }
}); });
// 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 // Start/stop lyrics active line updates based on playback state and visibility
$effect(() => { $effect(() => {
const lyricsVisible = lyricsSidebarVisible || isFocusModeOpen || isFullScreenOpen; const lyricsVisible = lyricsSidebarVisible || isFocusModeOpen || isFullScreenOpen;