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
This commit is contained in:
1 parent
5f4cfa5888
commit
3297257a24
3 files changed
+39
-14
No files matched your search
@@ -140,18 +140,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
const artists = Array.from(artistNames).slice(0, 5);
|
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) {
|
if (artists.length > 0) {
|
||||||
return `${artists.join('\n')}\n${songText}`;
|
return `${artists.join('\n')}\n${trackText}`;
|
||||||
}
|
}
|
||||||
return songText;
|
return trackText;
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.debug('Failed to fetch playlist artists:', 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)
|
// Get basic tooltip (no state mutation during render)
|
||||||
@@ -162,10 +171,7 @@
|
|||||||
// Return basic tooltip with combined count
|
// Return basic tooltip with combined count
|
||||||
const totalCount = getTotalTrackCount(playlist);
|
const totalCount = getTotalTrackCount(playlist);
|
||||||
const localCount = localTrackCounts.get(playlist.id) ?? 0;
|
const localCount = localTrackCounts.get(playlist.id) ?? 0;
|
||||||
const countText = localCount > 0
|
return formatTrackCount(totalCount, localCount);
|
||||||
? `${totalCount} Songs (${localCount} local)`
|
|
||||||
: `${totalCount} ${totalCount === 1 ? 'Song' : 'Songs'}`;
|
|
||||||
return countText;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load artist info for tooltip (called on hover, not during render)
|
// Load artist info for tooltip (called on hover, not during render)
|
||||||
@@ -176,16 +182,21 @@
|
|||||||
|
|
||||||
const totalCount = getTotalTrackCount(playlist);
|
const totalCount = getTotalTrackCount(playlist);
|
||||||
const localCount = localTrackCounts.get(playlist.id) ?? 0;
|
const localCount = localTrackCounts.get(playlist.id) ?? 0;
|
||||||
fetchPlaylistArtists(playlist.id, totalCount).then(tooltip => {
|
fetchPlaylistArtists(playlist.id, totalCount).then(baseTooltip => {
|
||||||
// Append local count info if there are local tracks
|
// Replace the song count line with properly formatted one including local count
|
||||||
const finalTooltip = localCount > 0
|
const countText = formatTrackCount(totalCount, localCount);
|
||||||
? tooltip.replace(/(\d+) (Song|Songs)/, `$1 $2 (${localCount} local)`)
|
const finalTooltip = baseTooltip.replace(/\d+ (Track|Tracks)/, countText);
|
||||||
: tooltip;
|
|
||||||
playlistTooltipCache.set(playlist.id, finalTooltip);
|
playlistTooltipCache.set(playlist.id, finalTooltip);
|
||||||
tooltipLoadingIds.delete(playlist.id);
|
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
|
// Load sort preference from localStorage
|
||||||
function loadSortPreference() {
|
function loadSortPreference() {
|
||||||
try {
|
try {
|
||||||
@@ -257,6 +268,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function refreshPlaylists() {
|
export function refreshPlaylists() {
|
||||||
|
playlistTooltipCache.clear();
|
||||||
loadUserPlaylists();
|
loadUserPlaylists();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,6 +280,13 @@
|
|||||||
loadLocalTrackCounts();
|
loadLocalTrackCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Call this when tracks are added/removed from a playlist
|
||||||
|
export function onPlaylistTracksChanged(playlistId: number) {
|
||||||
|
invalidatePlaylistTooltip(playlistId);
|
||||||
|
loadUserPlaylists();
|
||||||
|
loadLocalTrackCounts();
|
||||||
|
}
|
||||||
|
|
||||||
// Menu handling functions
|
// Menu handling functions
|
||||||
function closeMenu() {
|
function closeMenu() {
|
||||||
menuOpen = false;
|
menuOpen = false;
|
||||||
|
|||||||
@@ -494,6 +494,8 @@
|
|||||||
});
|
});
|
||||||
await loadPlaylist();
|
await loadPlaylist();
|
||||||
}
|
}
|
||||||
|
// Notify parent to refresh sidebar counts
|
||||||
|
onPlaylistUpdated?.();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to remove track from playlist:', err);
|
console.error('Failed to remove track from playlist:', err);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1235,6 +1235,7 @@
|
|||||||
}
|
}
|
||||||
sidebarRef?.refreshPlaylists();
|
sidebarRef?.refreshPlaylists();
|
||||||
sidebarRef?.refreshPlaylistSettings();
|
sidebarRef?.refreshPlaylistSettings();
|
||||||
|
sidebarRef?.refreshLocalTrackCounts();
|
||||||
}
|
}
|
||||||
|
|
||||||
function openImportPlaylist() {
|
function openImportPlaylist() {
|
||||||
@@ -2014,7 +2015,10 @@
|
|||||||
onLocalTrackPlay={handleLocalTrackPlay}
|
onLocalTrackPlay={handleLocalTrackPlay}
|
||||||
onLocalTrackPlayNext={queueLocalTrackNext}
|
onLocalTrackPlayNext={queueLocalTrackNext}
|
||||||
onLocalTrackPlayLater={queueLocalTrackLater}
|
onLocalTrackPlayLater={queueLocalTrackLater}
|
||||||
onPlaylistUpdated={() => sidebarRef?.refreshPlaylists()}
|
onPlaylistUpdated={() => {
|
||||||
|
sidebarRef?.refreshPlaylists();
|
||||||
|
sidebarRef?.refreshLocalTrackCounts();
|
||||||
|
}}
|
||||||
onPlaylistDeleted={() => { sidebarRef?.refreshPlaylists(); navGoBack(); }}
|
onPlaylistDeleted={() => { sidebarRef?.refreshPlaylists(); navGoBack(); }}
|
||||||
/>
|
/>
|
||||||
{:else if activeView === 'favorites'}
|
{:else if activeView === 'favorites'}
|
||||||
|
|||||||
Reference in new issue
Block a user