From 3297257a2439ed88bb8ebfa0606494b02e441092 Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 16 Jan 2026 06:39:08 -0600 Subject: [PATCH] Fix tooltip updates and change Song to Track terminology - Update onPlaylistUpdated callback to also refresh local track counts - Change all Song/Songs references to Track/Tracks in Sidebar tooltips - Ensure tooltip cache is properly invalidated when tracks are modified --- src/lib/components/Sidebar.svelte | 45 +++++++++++++------ .../views/PlaylistDetailView.svelte | 2 + src/routes/+page.svelte | 6 ++- 3 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/lib/components/Sidebar.svelte b/src/lib/components/Sidebar.svelte index 2bddd157e..15b25c2e9 100644 --- a/src/lib/components/Sidebar.svelte +++ b/src/lib/components/Sidebar.svelte @@ -140,18 +140,27 @@ } const artists = Array.from(artistNames).slice(0, 5); - const songText = `${trackCount} ${trackCount === 1 ? 'Song' : 'Songs'}`; + const trackText = `${trackCount} ${trackCount === 1 ? 'Track' : 'Tracks'}`; if (artists.length > 0) { - return `${artists.join('\n')}\n${songText}`; + return `${artists.join('\n')}\n${trackText}`; } - return songText; + return trackText; } } catch (err) { console.debug('Failed to fetch playlist artists:', err); } - return `${trackCount} ${trackCount === 1 ? 'Song' : 'Songs'}`; + return `${trackCount} ${trackCount === 1 ? 'Track' : 'Tracks'}`; + } + + // Format track count text with proper plural + function formatTrackCount(total: number, localCount: number): string { + const plural = total === 1 ? 'Track' : 'Tracks'; + if (localCount > 0) { + return `${total} ${plural} (${localCount} local)`; + } + return `${total} ${plural}`; } // Get basic tooltip (no state mutation during render) @@ -162,10 +171,7 @@ // Return basic tooltip with combined count const totalCount = getTotalTrackCount(playlist); const localCount = localTrackCounts.get(playlist.id) ?? 0; - const countText = localCount > 0 - ? `${totalCount} Songs (${localCount} local)` - : `${totalCount} ${totalCount === 1 ? 'Song' : 'Songs'}`; - return countText; + return formatTrackCount(totalCount, localCount); } // Load artist info for tooltip (called on hover, not during render) @@ -176,16 +182,21 @@ const totalCount = getTotalTrackCount(playlist); const localCount = localTrackCounts.get(playlist.id) ?? 0; - fetchPlaylistArtists(playlist.id, totalCount).then(tooltip => { - // Append local count info if there are local tracks - const finalTooltip = localCount > 0 - ? tooltip.replace(/(\d+) (Song|Songs)/, `$1 $2 (${localCount} local)`) - : tooltip; + fetchPlaylistArtists(playlist.id, totalCount).then(baseTooltip => { + // Replace the song count line with properly formatted one including local count + const countText = formatTrackCount(totalCount, localCount); + const finalTooltip = baseTooltip.replace(/\d+ (Track|Tracks)/, countText); playlistTooltipCache.set(playlist.id, finalTooltip); tooltipLoadingIds.delete(playlist.id); }); } + // Invalidate tooltip cache for a specific playlist (call when tracks change) + function invalidatePlaylistTooltip(playlistId: number) { + playlistTooltipCache.delete(playlistId); + tooltipLoadingIds.delete(playlistId); + } + // Load sort preference from localStorage function loadSortPreference() { try { @@ -257,6 +268,7 @@ } export function refreshPlaylists() { + playlistTooltipCache.clear(); loadUserPlaylists(); } @@ -268,6 +280,13 @@ loadLocalTrackCounts(); } + // Call this when tracks are added/removed from a playlist + export function onPlaylistTracksChanged(playlistId: number) { + invalidatePlaylistTooltip(playlistId); + loadUserPlaylists(); + loadLocalTrackCounts(); + } + // Menu handling functions function closeMenu() { menuOpen = false; diff --git a/src/lib/components/views/PlaylistDetailView.svelte b/src/lib/components/views/PlaylistDetailView.svelte index df9019e31..f7c59e8da 100644 --- a/src/lib/components/views/PlaylistDetailView.svelte +++ b/src/lib/components/views/PlaylistDetailView.svelte @@ -494,6 +494,8 @@ }); await loadPlaylist(); } + // Notify parent to refresh sidebar counts + onPlaylistUpdated?.(); } catch (err) { console.error('Failed to remove track from playlist:', err); } diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index ccbe5facb..a53d4a9ae 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1235,6 +1235,7 @@ } sidebarRef?.refreshPlaylists(); sidebarRef?.refreshPlaylistSettings(); + sidebarRef?.refreshLocalTrackCounts(); } function openImportPlaylist() { @@ -2014,7 +2015,10 @@ onLocalTrackPlay={handleLocalTrackPlay} onLocalTrackPlayNext={queueLocalTrackNext} onLocalTrackPlayLater={queueLocalTrackLater} - onPlaylistUpdated={() => sidebarRef?.refreshPlaylists()} + onPlaylistUpdated={() => { + sidebarRef?.refreshPlaylists(); + sidebarRef?.refreshLocalTrackCounts(); + }} onPlaylistDeleted={() => { sidebarRef?.refreshPlaylists(); navGoBack(); }} /> {:else if activeView === 'favorites'}