diff --git a/src/lib/components/PlaylistModal.svelte b/src/lib/components/PlaylistModal.svelte index f6c7db158..c61914e94 100644 --- a/src/lib/components/PlaylistModal.svelte +++ b/src/lib/components/PlaylistModal.svelte @@ -378,6 +378,8 @@ }); void logPlaylistAdd(trackIds, newPlaylist.id); } + // Update tracks_count to reflect added tracks (API returns 0 at creation) + newPlaylist.tracks_count = isLocalTracks ? 0 : trackIds.length; } onSuccess?.(newPlaylist); diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 60f7f8e8e..ff7308063 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1630,7 +1630,10 @@ openPlaylistModal('addTrack', trackIds, isLocal); } - function handlePlaylistCreated() { + function handlePlaylistCreated(playlist?: import('$lib/types').Playlist) { + const trackCount = playlistModalTrackIds.length; + const isLocal = playlistModalTracksAreLocal; + if (playlistModalMode === 'addTrack') { showToast('Track(s) added to playlist', 'success'); } else { @@ -1639,6 +1642,17 @@ sidebarRef?.refreshPlaylists(); sidebarRef?.refreshPlaylistSettings(); sidebarRef?.refreshLocalTrackCounts(); + + // If a newly created playlist is provided, ensure the sidebar has the correct count + // This handles API eventual consistency where tracks_count might be stale + if (playlist && playlist.id > 0 && trackCount > 0) { + // Small delay to let refreshPlaylists complete, then override with correct count + setTimeout(() => { + const qobuzCount = isLocal ? 0 : trackCount; + const localCount = isLocal ? trackCount : 0; + sidebarRef?.updatePlaylistCounts(playlist.id, qobuzCount, localCount); + }, 100); + } } function openImportPlaylist() {