fix: Use playQueueIndex for complete track data and add animated loading states
- Use playQueueIndex(0) instead of reading from queue store to get full track data - Fixes missing artwork, duration, and seekbar for first track - Add animated pill button with loading messages during radio creation - Add glowing blue effect on radio icon after successful creation - Loading messages: preparing, fetching artists, experimental notice
This commit is contained in:
1 parent
6c3ff71cdd
commit
4fc8c04bc1
1 file changed
+68
-19
@@ -6,7 +6,7 @@
|
|||||||
import TrackMenu from '../TrackMenu.svelte';
|
import TrackMenu from '../TrackMenu.svelte';
|
||||||
import { consumeContextTrackFocus, setPlaybackContext } from '$lib/stores/playbackContextStore';
|
import { consumeContextTrackFocus, setPlaybackContext } from '$lib/stores/playbackContextStore';
|
||||||
import { togglePlay } from '$lib/stores/playerStore';
|
import { togglePlay } from '$lib/stores/playerStore';
|
||||||
import { getQueue, syncQueueState } from '$lib/stores/queueStore';
|
import { getQueue, syncQueueState, playQueueIndex } from '$lib/stores/queueStore';
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
interface Track {
|
interface Track {
|
||||||
@@ -113,6 +113,8 @@
|
|||||||
let isFavorite = $state(false);
|
let isFavorite = $state(false);
|
||||||
let isFavoriteLoading = $state(false);
|
let isFavoriteLoading = $state(false);
|
||||||
let isRadioLoading = $state(false);
|
let isRadioLoading = $state(false);
|
||||||
|
let radioLoadingMessage = $state('');
|
||||||
|
let radioJustCreated = $state(false);
|
||||||
let similarArtists = $state<QobuzArtist[]>([]);
|
let similarArtists = $state<QobuzArtist[]>([]);
|
||||||
let similarArtistsLoading = $state(false);
|
let similarArtistsLoading = $state(false);
|
||||||
let similarArtistImageErrors = $state<Set<number>>(new Set());
|
let similarArtistImageErrors = $state<Set<number>>(new Set());
|
||||||
@@ -252,27 +254,31 @@
|
|||||||
if (isRadioLoading) return;
|
if (isRadioLoading) return;
|
||||||
|
|
||||||
isRadioLoading = true;
|
isRadioLoading = true;
|
||||||
|
radioJustCreated = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Show loading messages
|
||||||
|
radioLoadingMessage = 'Preparing the artist radio...';
|
||||||
|
await new Promise(resolve => setTimeout(resolve, 800));
|
||||||
|
|
||||||
|
radioLoadingMessage = 'Fetching similar artists';
|
||||||
const sessionId = await invoke<string>('create_artist_radio', {
|
const sessionId = await invoke<string>('create_artist_radio', {
|
||||||
artistId: artist.id,
|
artistId: artist.id,
|
||||||
artistName: artist.name
|
artistName: artist.name
|
||||||
});
|
});
|
||||||
console.log(`[Radio] Artist radio created: ${sessionId}`);
|
console.log(`[Radio] Artist radio created: ${sessionId}`);
|
||||||
|
|
||||||
// Sync queue state from backend
|
radioLoadingMessage = 'Radio function is still experimental...';
|
||||||
await syncQueueState();
|
await new Promise(resolve => setTimeout(resolve, 400));
|
||||||
|
|
||||||
// Get the first track from queue and start playback
|
// Play first track from queue
|
||||||
const queue = getQueue();
|
const firstTrack = await playQueueIndex(0);
|
||||||
console.log(`[Radio] Queue length: ${queue.length}, onTrackPlay defined: ${!!onTrackPlay}`);
|
|
||||||
|
|
||||||
if (queue.length > 0 && onTrackPlay) {
|
if (firstTrack && onTrackPlay) {
|
||||||
const firstTrack = queue[0];
|
|
||||||
console.log(`[Radio] First track:`, firstTrack);
|
console.log(`[Radio] First track:`, firstTrack);
|
||||||
// Start playback using the onTrackPlay callback
|
// Start playback using the onTrackPlay callback
|
||||||
onTrackPlay({
|
onTrackPlay({
|
||||||
id: Number(firstTrack.id),
|
id: firstTrack.id,
|
||||||
title: firstTrack.title,
|
title: firstTrack.title,
|
||||||
artist: firstTrack.artist,
|
artist: firstTrack.artist,
|
||||||
album: firstTrack.album,
|
album: firstTrack.album,
|
||||||
@@ -284,14 +290,19 @@
|
|||||||
samplingRate: firstTrack.sample_rate ?? undefined,
|
samplingRate: firstTrack.sample_rate ?? undefined,
|
||||||
});
|
});
|
||||||
console.log(`[Radio] Started playback of track ${firstTrack.id}`);
|
console.log(`[Radio] Started playback of track ${firstTrack.id}`);
|
||||||
|
|
||||||
|
// Mark as just created for visual feedback
|
||||||
|
radioJustCreated = true;
|
||||||
|
setTimeout(() => { radioJustCreated = false; }, 3000);
|
||||||
} else {
|
} else {
|
||||||
console.log(`[Radio] Cannot start playback - queue: ${queue.length}, onTrackPlay: ${!!onTrackPlay}`);
|
console.log(`[Radio] Cannot start playback - firstTrack: ${!!firstTrack}, onTrackPlay: ${!!onTrackPlay}`);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to create artist radio:', err);
|
console.error('Failed to create artist radio:', err);
|
||||||
// TODO: Show user-facing error toast if available
|
// TODO: Show user-facing error toast if available
|
||||||
} finally {
|
} finally {
|
||||||
isRadioLoading = false;
|
isRadioLoading = false;
|
||||||
|
radioLoadingMessage = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -307,14 +318,14 @@
|
|||||||
});
|
});
|
||||||
console.log(`[Radio] Track radio created: ${sessionId}`);
|
console.log(`[Radio] Track radio created: ${sessionId}`);
|
||||||
|
|
||||||
// Get the first track from queue and start playback
|
// Play first track from queue
|
||||||
const queue = getQueue();
|
const firstTrack = await playQueueIndex(0);
|
||||||
|
|
||||||
if (queue.length > 0 && onTrackPlay) {
|
if (firstTrack && onTrackPlay) {
|
||||||
const firstTrack = queue[0];
|
console.log(`[Radio] First track:`, firstTrack);
|
||||||
// Start playback using the onTrackPlay callback
|
// Start playback using the onTrackPlay callback
|
||||||
onTrackPlay({
|
onTrackPlay({
|
||||||
id: Number(firstTrack.id),
|
id: firstTrack.id,
|
||||||
title: firstTrack.title,
|
title: firstTrack.title,
|
||||||
artist: firstTrack.artist,
|
artist: firstTrack.artist,
|
||||||
album: firstTrack.album,
|
album: firstTrack.album,
|
||||||
@@ -726,11 +737,17 @@
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="radio-btn"
|
class="radio-btn"
|
||||||
|
class:loading={isRadioLoading}
|
||||||
|
class:glow={radioJustCreated}
|
||||||
onclick={createArtistRadio}
|
onclick={createArtistRadio}
|
||||||
disabled={isRadioLoading}
|
disabled={isRadioLoading}
|
||||||
title="Start Artist Radio"
|
title="Start Artist Radio"
|
||||||
>
|
>
|
||||||
<Radio size={24} />
|
{#if isRadioLoading}
|
||||||
|
<span class="loading-message">{radioLoadingMessage}</span>
|
||||||
|
{:else}
|
||||||
|
<Radio size={24} />
|
||||||
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="artist-stats">
|
<div class="artist-stats">
|
||||||
@@ -1356,20 +1373,52 @@
|
|||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
transition: all 150ms ease;
|
transition: all 300ms ease;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
.radio-btn:hover:not(:disabled) {
|
.radio-btn.loading {
|
||||||
|
width: auto;
|
||||||
|
min-width: 200px;
|
||||||
|
padding: 0 20px;
|
||||||
|
border-radius: 22px;
|
||||||
|
cursor: default;
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-btn.glow {
|
||||||
|
color: var(--accent-primary);
|
||||||
|
box-shadow: 0 0 20px rgba(96, 165, 250, 0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.radio-btn:hover:not(:disabled):not(.loading) {
|
||||||
background: var(--bg-hover);
|
background: var(--bg-hover);
|
||||||
color: var(--accent-primary);
|
color: var(--accent-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
.radio-btn:disabled {
|
.radio-btn:disabled:not(.loading) {
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
cursor: not-allowed;
|
cursor: not-allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.loading-message {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
animation: fadeIn 0.3s ease-in;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateY(-2px);
|
||||||
|
}
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
transform: translateY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.artist-stats {
|
.artist-stats {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
color: var(--text-muted);
|
color: var(--text-muted);
|
||||||
|
|||||||
Reference in new issue
Block a user