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
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ChevronRight, ImagePlus, Info, Edit3, BarChart2, WifiOff } from 'lucide-svelte';
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ChevronRight, ImagePlus, Edit3, BarChart2, WifiOff } from 'lucide-svelte';
|
||||
import AlbumMenu from '../AlbumMenu.svelte';
|
||||
import PlaylistCollage from '../PlaylistCollage.svelte';
|
||||
import PlaylistModal from '../PlaylistModal.svelte';
|
||||
@@ -152,6 +152,12 @@
|
||||
let localTracks = $state<LocalLibraryTrack[]>([]);
|
||||
let localTracksMap = $state<Map<number, LocalLibraryTrack>>(new Map());
|
||||
let hasLocalTracks = $derived(localTracks.length > 0);
|
||||
|
||||
// Total counts including local tracks
|
||||
let totalTrackCount = $derived((playlist?.tracks_count ?? 0) + localTracks.length);
|
||||
let localTracksDuration = $derived(localTracks.reduce((sum, t) => sum + t.duration_secs, 0));
|
||||
let totalDuration = $derived((playlist?.duration ?? 0) + localTracksDuration);
|
||||
|
||||
let loading = $state(true);
|
||||
let error = $state<string | null>(null);
|
||||
let playBtnHovered = $state(false);
|
||||
@@ -669,9 +675,9 @@
|
||||
<div class="playlist-info">
|
||||
<span class="owner">{playlist.owner.name}</span>
|
||||
<span class="separator">•</span>
|
||||
<span>{playlist.tracks_count} tracks</span>
|
||||
<span>{totalTrackCount} tracks{#if hasLocalTracks} <span class="local-count">({localTracks.length} local)</span>{/if}</span>
|
||||
<span class="separator">•</span>
|
||||
<span>{formatTotalDuration(playlist.duration)}</span>
|
||||
<span>{formatTotalDuration(totalDuration)}</span>
|
||||
{#if playlistStats && playlistStats.play_count > 0}
|
||||
<span class="separator">•</span>
|
||||
<span class="play-count" title="Times played">
|
||||
@@ -761,22 +767,8 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<span class="track-count">
|
||||
{displayTracks.length}{searchQuery ? ` / ${tracks.length + localTracks.length}` : ''} tracks
|
||||
{#if hasLocalTracks}
|
||||
<span class="local-count">({localTracks.length} local)</span>
|
||||
{/if}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- Local tracks notice -->
|
||||
{#if hasLocalTracks}
|
||||
<div class="local-notice">
|
||||
<Info size={14} />
|
||||
<span>Local tracks are only available on this device</span>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<!-- Track List -->
|
||||
<div class="track-list">
|
||||
<div class="track-list-header">
|
||||
@@ -1345,12 +1337,6 @@
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.track-count {
|
||||
margin-left: auto;
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.no-results {
|
||||
padding: 48px;
|
||||
text-align: center;
|
||||
@@ -1361,29 +1347,11 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Local tracks styles */
|
||||
.local-count {
|
||||
color: var(--accent-primary);
|
||||
margin-left: 4px;
|
||||
color: var(--text-muted);
|
||||
font-size: 0.9em;
|
||||
}
|
||||
|
||||
.local-notice {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 16px;
|
||||
margin-bottom: 16px;
|
||||
background-color: rgba(var(--accent-primary-rgb, 139, 92, 246), 0.1);
|
||||
border: 1px solid rgba(var(--accent-primary-rgb, 139, 92, 246), 0.2);
|
||||
border-radius: 8px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.local-notice :global(svg) {
|
||||
color: var(--accent-primary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.track-row-wrapper {
|
||||
display: flex;
|
||||
|
||||
@@ -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