feat(playlists): include local tracks in counts everywhere
- Add playlist_get_all_local_track_counts command to get local track counts for all playlists efficiently - PlaylistDetailView: show combined track count and duration in header, style local count with muted color, remove redundant count below - Sidebar: load and display local track counts in tooltips - PlaylistModal: show combined counts when selecting playlist to add to - PlaylistManagerView: show combined counts in both grid and list views - TrackRow: move local indicator to download column position, add placeholder for favorite column to maintain alignment, update tooltip - Remove local tracks notice banner (info now in tooltip) cc
This commit is contained in:
1 parent
d731805eca
commit
5f4cfa5888
8 files changed
+174
-61
No files matched your search
@@ -51,6 +51,7 @@
|
||||
let playlists = $state<Playlist[]>([]);
|
||||
let playlistSettings = $state<Map<number, PlaylistSettings>>(new Map());
|
||||
let playlistStats = $state<Map<number, PlaylistStats>>(new Map());
|
||||
let localTrackCounts = $state<Map<number, number>>(new Map());
|
||||
let loading = $state(true);
|
||||
|
||||
// Offline state
|
||||
@@ -190,10 +191,11 @@
|
||||
async function loadData() {
|
||||
loading = true;
|
||||
try {
|
||||
const [playlistsResult, settingsResult, statsResult] = await Promise.all([
|
||||
const [playlistsResult, settingsResult, statsResult, localCountsResult] = await Promise.all([
|
||||
invoke<Playlist[]>('get_user_playlists'),
|
||||
invoke<PlaylistSettings[]>('playlist_get_all_settings'),
|
||||
invoke<PlaylistStats[]>('playlist_get_all_stats')
|
||||
invoke<PlaylistStats[]>('playlist_get_all_stats'),
|
||||
invoke<Record<string, number>>('playlist_get_all_local_track_counts')
|
||||
]);
|
||||
|
||||
playlists = playlistsResult;
|
||||
@@ -209,6 +211,12 @@
|
||||
statsMap.set(s.qobuz_playlist_id, s);
|
||||
}
|
||||
playlistStats = statsMap;
|
||||
|
||||
const localCountsMap = new Map<number, number>();
|
||||
for (const [id, count] of Object.entries(localCountsResult)) {
|
||||
localCountsMap.set(Number(id), count);
|
||||
}
|
||||
localTrackCounts = localCountsMap;
|
||||
} catch (err) {
|
||||
console.error('Failed to load playlists:', err);
|
||||
} finally {
|
||||
@@ -216,6 +224,17 @@
|
||||
}
|
||||
}
|
||||
|
||||
// Get total track count including local tracks
|
||||
function getTotalTrackCount(playlist: Playlist): number {
|
||||
const localCount = localTrackCounts.get(playlist.id) ?? 0;
|
||||
return playlist.tracks_count + localCount;
|
||||
}
|
||||
|
||||
// Get local track count for a playlist
|
||||
function getLocalTrackCount(playlistId: number): number {
|
||||
return localTrackCounts.get(playlistId) ?? 0;
|
||||
}
|
||||
|
||||
function formatDuration(seconds: number): string {
|
||||
const hours = Math.floor(seconds / 3600);
|
||||
const mins = Math.floor((seconds % 3600) / 60);
|
||||
@@ -514,7 +533,7 @@
|
||||
</div>
|
||||
<div class="info">
|
||||
<span class="name">{playlist.name}</span>
|
||||
<span class="meta">{playlist.tracks_count} tracks</span>
|
||||
<span class="meta">{getTotalTrackCount(playlist)} tracks{#if getLocalTrackCount(playlist.id) > 0} <span class="local-count">({getLocalTrackCount(playlist.id)} local)</span>{/if}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -556,7 +575,7 @@
|
||||
<div class="info">
|
||||
<span class="name">{playlist.name}</span>
|
||||
<span class="meta">
|
||||
{playlist.tracks_count} tracks
|
||||
{getTotalTrackCount(playlist)} tracks{#if getLocalTrackCount(playlist.id) > 0} <span class="local-count">({getLocalTrackCount(playlist.id)} local)</span>{/if}
|
||||
{#if playlist.duration > 0}
|
||||
<span class="dot">.</span>
|
||||
{formatDuration(playlist.duration)}
|
||||
@@ -1065,6 +1084,11 @@
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.local-count {
|
||||
color: var(--text-muted);
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.dot {
|
||||
margin: 0 4px;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user