feat(favorites): wire album favorite button to Qobuz API
- Add album id to AlbumDetail interface and conversion - Add artist id to enable artist navigation from album view - Wire heart button in AlbumDetailView to call add_favorite/remove_favorite - Fix artist click to use actual artist id instead of hardcoded 0
This commit is contained in:
1 parent
ddbe6b5706
commit
af44e14b0b
2 files changed
+29
-3
No files matched your search
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { ArrowLeft, Play, Shuffle, Heart, Plus, MoreHorizontal } from 'lucide-svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
|
||||
@@ -17,6 +18,7 @@
|
||||
|
||||
interface Props {
|
||||
album: {
|
||||
id: string;
|
||||
artwork: string;
|
||||
title: string;
|
||||
artist: string;
|
||||
@@ -40,7 +42,27 @@
|
||||
|
||||
let currentTrack = $state<number | null>(null);
|
||||
let isFavorite = $state(false);
|
||||
let isFavoriteLoading = $state(false);
|
||||
let playBtnHovered = $state(false);
|
||||
|
||||
async function toggleFavorite() {
|
||||
if (isFavoriteLoading) return;
|
||||
|
||||
isFavoriteLoading = true;
|
||||
try {
|
||||
if (isFavorite) {
|
||||
await invoke('remove_favorite', { favType: 'album', itemId: album.id });
|
||||
isFavorite = false;
|
||||
} else {
|
||||
await invoke('add_favorite', { favType: 'album', itemId: album.id });
|
||||
isFavorite = true;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to toggle favorite:', err);
|
||||
} finally {
|
||||
isFavoriteLoading = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="album-detail">
|
||||
@@ -83,7 +105,7 @@
|
||||
<Shuffle size={18} />
|
||||
<span>Shuffle</span>
|
||||
</button>
|
||||
<button class="icon-btn" onclick={() => (isFavorite = !isFavorite)}>
|
||||
<button class="icon-btn" onclick={toggleFavorite} disabled={isFavoriteLoading}>
|
||||
<Heart
|
||||
size={20}
|
||||
color={isFavorite ? 'var(--accent-primary)' : 'white'}
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
interface QobuzAlbum {
|
||||
id: string;
|
||||
title: string;
|
||||
artist: { name: string };
|
||||
artist: { id?: number; name: string };
|
||||
image: { small?: string; thumbnail?: string; large?: string };
|
||||
release_date_original?: string;
|
||||
hires_streamable?: boolean;
|
||||
@@ -105,9 +105,11 @@
|
||||
}
|
||||
|
||||
interface AlbumDetail {
|
||||
id: string;
|
||||
artwork: string;
|
||||
title: string;
|
||||
artist: string;
|
||||
artistId?: number;
|
||||
year: string;
|
||||
label: string;
|
||||
genre: string;
|
||||
@@ -245,9 +247,11 @@
|
||||
: 'CD Quality';
|
||||
|
||||
return {
|
||||
id: album.id,
|
||||
artwork,
|
||||
title: album.title,
|
||||
artist: album.artist?.name || 'Unknown Artist',
|
||||
artistId: album.artist?.id,
|
||||
year: album.release_date_original?.split('-')[0] || '',
|
||||
label: album.label?.name || '',
|
||||
genre: album.genre?.name || '',
|
||||
@@ -1059,7 +1063,7 @@
|
||||
<AlbumDetailView
|
||||
album={selectedAlbum}
|
||||
onBack={goBack}
|
||||
onArtistClick={() => selectedAlbum && handleArtistClick(0)}
|
||||
onArtistClick={() => selectedAlbum?.artistId && handleArtistClick(selectedAlbum.artistId)}
|
||||
onTrackPlay={handleAlbumTrackPlay}
|
||||
onPlayAll={handlePlayAllAlbum}
|
||||
onShuffleAll={handleShuffleAlbum}
|
||||
|
||||
Reference in new issue
Block a user