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
This commit is contained in:
vicrodh committed 2026-01-29 19:24:13 -06:00
1 parent 4858faa696
commit defd2f0fe1
6 files changed
+94 -29

No files matched your search

+21 -2
View File
@@ -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 @@
<button
class="overlay-btn overlay-btn--minor"
class:is-active={isFavorite}
class:is-toggling={isToggling}
class:disabled={!favoriteAvailable}
type="button"
aria-disabled={!favoriteAvailable}
disabled={!favoriteAvailable}
aria-disabled={!favoriteAvailable || isToggling}
disabled={!favoriteAvailable || isToggling}
onclick={handleToggleFavorite}
title={isFavorite ? 'Remove from favorites' : 'Add to favorites'}
>
@@ -466,6 +471,20 @@
transform: none;
}
.overlay-btn.is-toggling {
cursor: wait;
animation: favorite-pulse 0.8s ease-in-out infinite;
}
@keyframes favorite-pulse {
0%, 100% {
opacity: 0.5;
}
50% {
opacity: 1;
}
}
.overlay-menu {
display: flex;
align-items: center;