Connect playlist count callback for single source of truth
Wire onPlaylistCountUpdate from PlaylistDetailView to Sidebar's updatePlaylistCounts method in +page.svelte. This ensures the sidebar displays accurate track counts from the database instead of calculated values that could drift out of sync.
This commit is contained in:
1 parent
7292635210
commit
aeb13b9ffc
6 files changed
+146
-3
No files matched your search
@@ -287,6 +287,19 @@
|
||||
loadLocalTrackCounts();
|
||||
}
|
||||
|
||||
// Update counts for a specific playlist (single source of truth from detail view)
|
||||
export function updatePlaylistCounts(playlistId: number, qobuzCount: number, localCount: number) {
|
||||
// Update Qobuz count in userPlaylists
|
||||
userPlaylists = userPlaylists.map(p =>
|
||||
p.id === playlistId ? { ...p, tracks_count: qobuzCount } : p
|
||||
);
|
||||
// Update local count
|
||||
localTrackCounts.set(playlistId, localCount);
|
||||
localTrackCounts = new Map(localTrackCounts); // Trigger reactivity
|
||||
// Invalidate tooltip cache for this playlist
|
||||
invalidatePlaylistTooltip(playlistId);
|
||||
}
|
||||
|
||||
// Menu handling functions
|
||||
function closeMenu() {
|
||||
menuOpen = false;
|
||||
|
||||
@@ -132,6 +132,7 @@
|
||||
onLocalTrackPlayNext?: (track: LocalLibraryTrack) => void;
|
||||
onLocalTrackPlayLater?: (track: LocalLibraryTrack) => void;
|
||||
onSetLocalQueue?: (trackIds: number[]) => void;
|
||||
onPlaylistCountUpdate?: (playlistId: number, qobuzCount: number, localCount: number) => void;
|
||||
onPlaylistUpdated?: () => void;
|
||||
onPlaylistDeleted?: (playlistId: number) => void;
|
||||
activeTrackId?: number | null;
|
||||
@@ -158,6 +159,7 @@
|
||||
onLocalTrackPlayNext,
|
||||
onLocalTrackPlayLater,
|
||||
onSetLocalQueue,
|
||||
onPlaylistCountUpdate,
|
||||
onPlaylistUpdated,
|
||||
onPlaylistDeleted,
|
||||
activeTrackId = null,
|
||||
@@ -253,6 +255,15 @@
|
||||
}
|
||||
});
|
||||
|
||||
// Notify parent of actual track counts after loading (single source of truth)
|
||||
$effect(() => {
|
||||
if (playlist && !loading) {
|
||||
const qobuzCount = playlist.tracks_count ?? 0;
|
||||
const localCount = localTracks.length;
|
||||
onPlaylistCountUpdate?.(playlistId, qobuzCount, localCount);
|
||||
}
|
||||
});
|
||||
|
||||
async function loadLocalTracks() {
|
||||
try {
|
||||
const result = await invoke<PlaylistLocalTrack[]>('playlist_get_local_tracks_with_position', { playlistId });
|
||||
|
||||
@@ -2019,6 +2019,9 @@
|
||||
onLocalTrackPlayNext={queueLocalTrackNext}
|
||||
onLocalTrackPlayLater={queueLocalTrackLater}
|
||||
onSetLocalQueue={handleSetLocalQueue}
|
||||
onPlaylistCountUpdate={(playlistId, qobuzCount, localCount) =>
|
||||
sidebarRef?.updatePlaylistCounts(playlistId, qobuzCount, localCount)
|
||||
}
|
||||
onPlaylistUpdated={() => {
|
||||
sidebarRef?.refreshPlaylists();
|
||||
sidebarRef?.refreshLocalTrackCounts();
|
||||
|
||||
Reference in new issue
Block a user