From defd2f0fe11ad6ac22ed182b5edf913b8e94054c Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Thu, 29 Jan 2026 19:24:13 -0600 Subject: [PATCH] fix(favorites): ensure favorites sync with Qobuz API and show loading state Issues fixed: - playbackService was bypassing the favorites store, causing UI desync - Album favorites weren't loaded on login (only track favorites were) - No visual feedback while favorite API call was in progress Changes: - Add toggling state tracking to favoritesStore and albumFavoritesStore - Add isTrackToggling() and isAlbumToggling() exports - Prevent double-toggle while API call is in progress - Update TrackRow and AlbumCard to show pulse animation while toggling - Update playbackService to use store's toggle (centralized API calls) - Load both track and album favorites on login --- src/lib/components/AlbumCard.svelte | 23 ++++++++++++++++-- src/lib/components/TrackRow.svelte | 21 +++++++++++++++++ src/lib/services/playbackService.ts | 34 ++++++++++----------------- src/lib/stores/albumFavoritesStore.ts | 17 +++++++++++++- src/lib/stores/favoritesStore.ts | 22 +++++++++++++++-- src/routes/+page.svelte | 6 +++-- 6 files changed, 94 insertions(+), 29 deletions(-) diff --git a/src/lib/components/AlbumCard.svelte b/src/lib/components/AlbumCard.svelte index ff2858a57..068ff4ee8 100644 --- a/src/lib/components/AlbumCard.svelte +++ b/src/lib/components/AlbumCard.svelte @@ -5,6 +5,7 @@ import { subscribe as subscribeAlbumFavorites, isAlbumFavorite, + isAlbumToggling, loadAlbumFavorites, toggleAlbumFavorite } from '$lib/stores/albumFavoritesStore'; @@ -86,6 +87,7 @@ const artistDuration = $derived(artistOverflow > 0 ? `${(artistOverflow + 16) / tickerSpeed}s` : '0s'); let favoriteFromStore = $state(false); + let isToggling = $state(false); const isFavorite = $derived(albumId ? favoriteFromStore : false); const hasMenu = $derived(!!(onPlayNext || onPlayLater || onShareQobuz || onShareSonglink || onDownload)); const showFavoriteButton = $derived(showFavorite ?? !!albumId); @@ -158,8 +160,10 @@ if (albumId) { void loadAlbumFavorites(); favoriteFromStore = isAlbumFavorite(albumId); + isToggling = isAlbumToggling(albumId); const unsubscribe = subscribeAlbumFavorites(() => { favoriteFromStore = isAlbumFavorite(albumId); + isToggling = isAlbumToggling(albumId); }); return () => unsubscribe(); } @@ -217,10 +221,11 @@