feat(ui): add playlist suggestions component and service

- Create PlaylistSuggestions.svelte component with:
  - Pool management (60 tracks, show 6 at a time)
  - Pagination/rotation on refresh
  - Loading, empty, and error states
  - Add (+) and dismiss (-) track actions
  - Album art display
  - Reason tooltip support (dev mode)

- Create playlistSuggestionsService.ts with:
  - MBID resolution from artist names (batched)
  - TypeScript types for SuggestedTrack, SuggestionResult
  - localStorage helpers for dismissed tracks
  - Qobuz album art URL generation

- Integrate into PlaylistDetailView:
  - Show suggestions at bottom of playlist track list
  - Extract unique artists from playlist for suggestions
  - Add track to playlist via add_tracks_to_playlist command
  - Hide when searching
This commit is contained in:
vicrodh committed 2026-01-27 11:48:48 -06:00
1 parent cadb346e32
commit f0aa539849
3 files changed
+743

No files matched your search

@@ -7,6 +7,8 @@
import { invoke } from '@tauri-apps/api/core';
import { open } from '@tauri-apps/plugin-dialog';
import TrackRow from '../TrackRow.svelte';
import PlaylistSuggestions from '../PlaylistSuggestions.svelte';
import { extractUniqueArtists } from '$lib/services/playlistSuggestionsService';
import { type OfflineCacheStatus } from '$lib/stores/offlineCacheState';
import {
subscribe as subscribeOffline,
@@ -192,6 +194,15 @@
let localTracksDuration = $derived(localTracks.reduce((sum, t) => sum + t.duration_secs, 0));
let totalDuration = $derived((playlist?.duration ?? 0) + localTracksDuration);
// Playlist suggestions: extract unique artists from Qobuz tracks (not local)
const playlistArtists = $derived(
extractUniqueArtists(tracks.filter(t => !t.isLocal))
);
// Track IDs to exclude from suggestions (already in playlist)
const excludeTrackIds = $derived(
tracks.filter(t => !t.isLocal).map(t => t.id)
);
let loading = $state(true);
let error = $state<string | null>(null);
let scrollContainer: HTMLDivElement | null = $state(null);
@@ -1175,6 +1186,23 @@
}
}
// Add a suggested track to the playlist
async function handleAddSuggestedTrack(trackId: number) {
try {
await invoke('add_tracks_to_playlist', {
playlistId,
trackIds: [trackId]
});
// Reload to show the new track
await loadPlaylist();
notifyParentOfCounts();
onPlaylistUpdated?.();
} catch (err) {
console.error('Failed to add suggested track:', err);
throw err; // Re-throw so the suggestions component knows it failed
}
}
async function handlePlayAll() {
// Get all display tracks (Qobuz + local, respecting search/sort)
const allTracks = displayTracks;
@@ -1647,6 +1675,17 @@
{/if}
</div>
<!-- Playlist Suggestions -->
{#if playlist && !searchQuery && playlistArtists.length > 0}
<PlaylistSuggestions
playlistId={playlistId}
artists={playlistArtists}
excludeTrackIds={excludeTrackIds}
onAddTrack={handleAddSuggestedTrack}
showReasons={false}
/>
{/if}
{/if}
</div>