Fix local tracks not being added to queue from playlists

- Update handlePlayAll to include both Qobuz and local tracks
- Update handlePlayAllNext and handlePlayAllLater similarly
- Add onSetLocalQueue prop to mark local tracks in queue store
- Connect prop to handleSetLocalQueue in +page.svelte
This commit is contained in:
vicrodh committed 2026-01-16 06:51:59 -06:00
1 parent 825534621a
commit 9366388041
2 files changed
+77 -30

No files matched your search

@@ -116,6 +116,7 @@
onLocalTrackPlay?: (track: LocalLibraryTrack) => void; onLocalTrackPlay?: (track: LocalLibraryTrack) => void;
onLocalTrackPlayNext?: (track: LocalLibraryTrack) => void; onLocalTrackPlayNext?: (track: LocalLibraryTrack) => void;
onLocalTrackPlayLater?: (track: LocalLibraryTrack) => void; onLocalTrackPlayLater?: (track: LocalLibraryTrack) => void;
onSetLocalQueue?: (trackIds: number[]) => void;
onPlaylistUpdated?: () => void; onPlaylistUpdated?: () => void;
onPlaylistDeleted?: (playlistId: number) => void; onPlaylistDeleted?: (playlistId: number) => void;
activeTrackId?: number | null; activeTrackId?: number | null;
@@ -141,6 +142,7 @@
onLocalTrackPlay, onLocalTrackPlay,
onLocalTrackPlayNext, onLocalTrackPlayNext,
onLocalTrackPlayLater, onLocalTrackPlayLater,
onSetLocalQueue,
onPlaylistUpdated, onPlaylistUpdated,
onPlaylistDeleted, onPlaylistDeleted,
activeTrackId = null, activeTrackId = null,
@@ -502,30 +504,50 @@
} }
async function handlePlayAll() { async function handlePlayAll() {
if (tracks.length > 0 && onTrackPlay) { // Get all display tracks (Qobuz + local, respecting search/sort)
// Set queue with all tracks and play first const allTracks = displayTracks;
const queueTracks = tracks.map(t => ({ if (allTracks.length === 0) return;
id: t.id,
title: t.title,
artist: t.artist || 'Unknown Artist',
album: t.album || playlist?.name || 'Playlist',
duration_secs: t.durationSeconds,
artwork_url: t.albumArt || getPlaylistImage(),
hires: t.hires ?? false,
bit_depth: t.bitDepth ?? null,
sample_rate: t.samplingRate ?? null,
}));
try { // Build queue tracks, using absolute ID for local tracks
await invoke('set_queue', { tracks: queueTracks, startIndex: 0 }); const queueTracks = allTracks.map(t => ({
onTrackPlay(tracks[0]); id: t.isLocal ? Math.abs(t.id) : t.id,
title: t.title,
artist: t.artist || 'Unknown Artist',
album: t.album || playlist?.name || 'Playlist',
duration_secs: t.durationSeconds,
artwork_url: t.albumArt || getPlaylistImage(),
hires: t.hires ?? false,
bit_depth: t.bitDepth ?? null,
sample_rate: t.samplingRate != null ? (t.isLocal ? t.samplingRate * 1000 : t.samplingRate) : null,
}));
// Increment play count // Collect local track IDs (original positive IDs)
const stats = await invoke<PlaylistStats>('playlist_increment_play_count', { playlistId }); const localIds = allTracks
playlistStats = stats; .filter(t => t.isLocal)
} catch (err) { .map(t => Math.abs(t.id));
console.error('Failed to set queue:', err);
try {
await invoke('set_queue', { tracks: queueTracks, startIndex: 0 });
// Tell parent about local tracks in queue
if (localIds.length > 0) {
onSetLocalQueue?.(localIds);
} }
// Play first track (handle local vs Qobuz)
const firstTrack = allTracks[0];
if (firstTrack.isLocal && onLocalTrackPlay) {
const localTrack = localTracks.find(t => t.id === Math.abs(firstTrack.id));
if (localTrack) onLocalTrackPlay(localTrack);
} else if (onTrackPlay) {
onTrackPlay(firstTrack);
}
// Increment play count
const stats = await invoke<PlaylistStats>('playlist_increment_play_count', { playlistId });
playlistStats = stats;
} catch (err) {
console.error('Failed to set queue:', err);
} }
} }
@@ -554,14 +576,21 @@
} }
async function handlePlayAllNext() { async function handlePlayAllNext() {
if (tracks.length === 0) return; const allTracks = displayTracks;
if (allTracks.length === 0) return;
// Collect local track IDs to add to set
const localIds = allTracks
.filter(t => t.isLocal)
.map(t => Math.abs(t.id));
// Add in reverse order so first track ends up right after current // Add in reverse order so first track ends up right after current
for (let i = tracks.length - 1; i >= 0; i--) { for (let i = allTracks.length - 1; i >= 0; i--) {
const t = tracks[i]; const t = allTracks[i];
try { try {
await invoke('add_to_queue_next', { await invoke('add_to_queue_next', {
track: { track: {
id: t.id, id: t.isLocal ? Math.abs(t.id) : t.id,
title: t.title, title: t.title,
artist: t.artist || 'Unknown Artist', artist: t.artist || 'Unknown Artist',
album: t.album || playlist?.name || 'Playlist', album: t.album || playlist?.name || 'Playlist',
@@ -569,19 +598,26 @@
artwork_url: t.albumArt || getPlaylistImage(), artwork_url: t.albumArt || getPlaylistImage(),
hires: t.hires ?? false, hires: t.hires ?? false,
bit_depth: t.bitDepth ?? null, bit_depth: t.bitDepth ?? null,
sample_rate: t.samplingRate ?? null, sample_rate: t.samplingRate != null ? (t.isLocal ? t.samplingRate * 1000 : t.samplingRate) : null,
} }
}); });
} catch (err) { } catch (err) {
console.error('Failed to add track next:', err); console.error('Failed to add track next:', err);
} }
} }
// Tell parent about local tracks added to queue
if (localIds.length > 0) {
onSetLocalQueue?.(localIds);
}
} }
async function handlePlayAllLater() { async function handlePlayAllLater() {
if (tracks.length === 0) return; const allTracks = displayTracks;
const queueTracks = tracks.map(t => ({ if (allTracks.length === 0) return;
id: t.id,
const queueTracks = allTracks.map(t => ({
id: t.isLocal ? Math.abs(t.id) : t.id,
title: t.title, title: t.title,
artist: t.artist || 'Unknown Artist', artist: t.artist || 'Unknown Artist',
album: t.album || playlist?.name || 'Playlist', album: t.album || playlist?.name || 'Playlist',
@@ -589,11 +625,21 @@
artwork_url: t.albumArt || getPlaylistImage(), artwork_url: t.albumArt || getPlaylistImage(),
hires: t.hires ?? false, hires: t.hires ?? false,
bit_depth: t.bitDepth ?? null, bit_depth: t.bitDepth ?? null,
sample_rate: t.samplingRate ?? null, sample_rate: t.samplingRate != null ? (t.isLocal ? t.samplingRate * 1000 : t.samplingRate) : null,
})); }));
// Collect local track IDs
const localIds = allTracks
.filter(t => t.isLocal)
.map(t => Math.abs(t.id));
try { try {
await invoke('add_tracks_to_queue', { tracks: queueTracks }); await invoke('add_tracks_to_queue', { tracks: queueTracks });
// Tell parent about local tracks added to queue
if (localIds.length > 0) {
onSetLocalQueue?.(localIds);
}
} catch (err) { } catch (err) {
console.error('Failed to add to queue:', err); console.error('Failed to add to queue:', err);
} }
+1
View File
@@ -2018,6 +2018,7 @@
onLocalTrackPlay={handleLocalTrackPlay} onLocalTrackPlay={handleLocalTrackPlay}
onLocalTrackPlayNext={queueLocalTrackNext} onLocalTrackPlayNext={queueLocalTrackNext}
onLocalTrackPlayLater={queueLocalTrackLater} onLocalTrackPlayLater={queueLocalTrackLater}
onSetLocalQueue={handleSetLocalQueue}
onPlaylistUpdated={() => { onPlaylistUpdated={() => {
sidebarRef?.refreshPlaylists(); sidebarRef?.refreshPlaylists();
sidebarRef?.refreshLocalTrackCounts(); sidebarRef?.refreshLocalTrackCounts();