feat(favorites): implement local SQLite persistence for favorites

This ensures favorites sync properly across all views (album detail,
continue listening, etc.) by using local persistence as the source
of truth for UI, with API calls for actual operations.

Backend (Rust):
- Add favorites_cache.rs module with SQLite tables:
  - favorite_tracks (track_id INTEGER PRIMARY KEY)
  - favorite_albums (album_id TEXT PRIMARY KEY)
  - favorite_artists (artist_id INTEGER PRIMARY KEY)
- Add Tauri commands for cache operations:
  - get_cached_favorite_* - read from local cache
  - cache_favorite_* / uncache_favorite_* - add/remove single items
  - sync_cached_favorite_* - bulk sync from API data
  - clear_favorites_cache - for logout

Frontend:
- Rewrite favoritesStore.ts to use persistence:
  - loadFavorites(): Load from cache first, then sync from API
  - toggleFavorite(): API call first → update cache on success
  - No optimistic updates - UI shows loading state until confirmed
- Rewrite albumFavoritesStore.ts with same pattern
- Create artistFavoritesStore.ts for artist favorites
- Update +page.svelte to load all favorites on login
- Update FavoritesView to sync cache when loading from API

Sync strategy:
- On login: Fetch from Qobuz API → sync to local cache
- On toggle: API call → on success → update local cache → notify UI
- FavoritesView reads from API and syncs local cache
- All other views read from local cache (instant UI)
This commit is contained in:
vicrodh committed 2026-01-29 19:42:04 -06:00
1 parent defd2f0fe1
commit 4c606e029e
8 files changed
+929 -72

No files matched your search

+18
View File
@@ -190,6 +190,9 @@ pub fn run() {
// Initialize favorites preferences state
let favorites_prefs_state = config::favorites_preferences::FavoritesPreferencesState::new()
.expect("Failed to initialize favorites preferences");
// Initialize favorites cache state (local persistence for favorite IDs)
let favorites_cache_state = config::favorites_cache::FavoritesCacheState::new()
.expect("Failed to initialize favorites cache");
// Initialize tray settings state
let tray_settings_state = config::tray_settings::TraySettingsState::new()
.expect("Failed to initialize tray settings");
@@ -437,6 +440,7 @@ pub fn run() {
.manage(offline_state)
.manage(playback_prefs_state)
.manage(favorites_prefs_state)
.manage(favorites_cache_state)
.manage(tray_settings_state)
.manage(updates_state)
.manage(musicbrainz_state)
@@ -775,6 +779,20 @@ pub fn run() {
config::playback_preferences::set_show_context_icon,
config::favorites_preferences::get_favorites_preferences,
config::favorites_preferences::save_favorites_preferences,
// Favorites cache commands (local persistence)
config::favorites_cache::get_cached_favorite_tracks,
config::favorites_cache::get_cached_favorite_albums,
config::favorites_cache::get_cached_favorite_artists,
config::favorites_cache::cache_favorite_track,
config::favorites_cache::uncache_favorite_track,
config::favorites_cache::cache_favorite_album,
config::favorites_cache::uncache_favorite_album,
config::favorites_cache::cache_favorite_artist,
config::favorites_cache::uncache_favorite_artist,
config::favorites_cache::sync_cached_favorite_tracks,
config::favorites_cache::sync_cached_favorite_albums,
config::favorites_cache::sync_cached_favorite_artists,
config::favorites_cache::clear_favorites_cache,
// Updates commands
updates::get_update_preferences,
updates::set_update_check_on_launch,