feat(toast): buffering toast with shimmer effect, persistent until loaded

- Add 'buffering' toast type that doesn't auto-hide
- Add shimmer animation to "Buffering" text
- Add spinning loader icon for buffering state
- Toast shows "Buffering... [track name]" format
- Dismiss buffering toast when track loads or on error
- Remove callback pattern, use toastStore directly in services

fix(artwork): show empty placeholder when no artwork available

- NowPlayingBar shows empty placeholder instead of Play icon
- Miniplayer shows empty placeholder instead of Play icon
- Prevents showing incorrect CD placeholder on session restore
This commit is contained in:
vicrodh committed 2026-01-12 09:06:58 -06:00
1 parent 434f8d8a67
commit e93144e5ef
7 files changed
+131 -62

No files matched your search

+2 -8
View File
@@ -247,9 +247,7 @@
{#if artwork}
<img src={artwork} alt={trackTitle} class="artwork" />
{:else}
<div class="artwork-placeholder">
<Play size={14} />
</div>
<div class="artwork-placeholder"></div>
{/if}
<!-- Artwork Preview on Hover -->
@@ -558,11 +556,7 @@
width: 56px;
height: 56px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.1);
display: flex;
align-items: center;
justify-content: center;
color: rgba(255, 255, 255, 0.4);
background: rgba(255, 255, 255, 0.06);
}
.artwork-preview {
+64 -5
View File
@@ -1,32 +1,46 @@
<script lang="ts">
import { onMount } from 'svelte';
import { CheckCircle, AlertCircle, Info, X } from 'lucide-svelte';
import { CheckCircle, AlertCircle, Info, Loader2, X } from 'lucide-svelte';
interface Props {
message: string;
type?: 'success' | 'error' | 'info';
type?: 'success' | 'error' | 'info' | 'buffering';
persistent?: boolean;
onClose: () => void;
}
let { message, type = 'success', onClose }: Props = $props();
let { message, type = 'success', persistent = false, onClose }: Props = $props();
onMount(() => {
// Don't auto-close persistent toasts (buffering)
if (persistent) return;
const timer = setTimeout(onClose, 4000);
return () => clearTimeout(timer);
});
</script>
<div class="toast" class:success={type === 'success'} class:error={type === 'error'} class:info={type === 'info'}>
<div class="toast" class:success={type === 'success'} class:error={type === 'error'} class:info={type === 'info'} class:buffering={type === 'buffering'}>
<div class="icon">
{#if type === 'success'}
<CheckCircle size={20} />
{:else if type === 'error'}
<AlertCircle size={20} />
{:else if type === 'buffering'}
<Loader2 size={20} class="spinning" />
{:else}
<Info size={20} />
{/if}
</div>
<span class="message">{message}</span>
{#if type === 'buffering'}
<span class="message">
<span class="shimmer-text">Buffering</span>
<span class="dots">...</span>
<span class="track-name">{message}</span>
</span>
{:else}
<span class="message">{message}</span>
{/if}
<button class="close-btn" onclick={onClose}>
<X size={16} />
</button>
@@ -78,11 +92,56 @@
color: var(--accent-primary);
}
.toast.buffering .icon {
color: var(--accent-primary);
}
.toast.buffering .icon :global(.spinning) {
animation: spin 1s linear infinite;
}
@keyframes spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.message {
font-size: 14px;
color: var(--text-primary);
}
/* Shimmer effect for buffering text */
.shimmer-text {
background: linear-gradient(
90deg,
var(--text-primary) 0%,
var(--accent-primary) 25%,
var(--text-primary) 50%,
var(--accent-primary) 75%,
var(--text-primary) 100%
);
background-size: 200% 100%;
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
animation: shimmer 2s ease-in-out infinite;
font-weight: 500;
}
@keyframes shimmer {
0% { background-position: 200% 0; }
100% { background-position: -200% 0; }
}
.dots {
color: var(--text-muted);
margin-right: 8px;
}
.track-name {
color: var(--text-secondary);
}
.close-btn {
background: none;
border: none;
+13 -12
View File
@@ -34,19 +34,17 @@ export interface MediaMetadata {
coverUrl: string | null;
}
// ============ Callbacks ============
// These are set by the consumer (e.g., +page.svelte) to handle UI feedback
// ============ Toast Integration ============
// Use the toast store directly for buffering toast support
let toastCallback: ((message: string, type: 'success' | 'error' | 'info') => void) | null = null;
import {
showToast as storeShowToast,
dismissBuffering,
type ToastType
} from '$lib/stores/toastStore';
export function setToastCallback(callback: (message: string, type: 'success' | 'error' | 'info') => void): void {
toastCallback = callback;
}
function showToast(message: string, type: 'success' | 'error' | 'info'): void {
if (toastCallback) {
toastCallback(message, type);
}
function showToast(message: string, type: ToastType): void {
storeShowToast(message, type);
}
// ============ Core Playback ============
@@ -65,7 +63,7 @@ export async function playTrack(
try {
if (showLoadingToast) {
showToast(`Loading: ${track.title}`, 'info');
showToast(track.title, 'buffering');
}
// Use appropriate playback command
@@ -75,6 +73,8 @@ export async function playTrack(
await invoke('play_track', { trackId: track.id });
}
// Dismiss buffering toast and show success
dismissBuffering();
setIsPlaying(true);
showToast(`Playing: ${track.title}`, 'success');
@@ -125,6 +125,7 @@ export async function playTrack(
return true;
} catch (err) {
console.error('Failed to play track:', err);
dismissBuffering();
showToast(`Playback error: ${err}`, 'error');
setIsPlaying(false);
return false;
+4 -11
View File
@@ -14,20 +14,13 @@ import {
} from '$lib/stores/queueStore';
import { addTrackToFavorites } from '$lib/services/playbackService';
import { openPlaylistModal } from '$lib/stores/uiStore';
import { showToast as storeShowToast, type ToastType } from '$lib/stores/toastStore';
import type { QobuzTrack, Track, PlaylistTrack, LocalLibraryTrack } from '$lib/types';
// ============ Toast Callback ============
// ============ Toast Integration ============
let toastCallback: ((message: string, type: 'success' | 'error' | 'info') => void) | null = null;
export function setToastCallback(callback: (message: string, type: 'success' | 'error' | 'info') => void): void {
toastCallback = callback;
}
function showToast(message: string, type: 'success' | 'error' | 'info'): void {
if (toastCallback) {
toastCallback(message, type);
}
function showToast(message: string, type: ToastType): void {
storeShowToast(message, type);
}
// ============ Queue Builders ============
+45 -12
View File
@@ -4,16 +4,20 @@
* Manages toast notifications across the app with auto-hide and queue support.
*/
export type ToastType = 'success' | 'error' | 'info';
export type ToastType = 'success' | 'error' | 'info' | 'buffering';
export interface Toast {
message: string;
type: ToastType;
persistent?: boolean;
}
// Current toast state
let currentToast: Toast | null = null;
// Track buffering toast specifically so we can dismiss it
let bufferingToastActive = false;
// Auto-hide timeout
let hideTimeout: ReturnType<typeof setTimeout> | null = null;
@@ -27,10 +31,17 @@ export function getToast(): Toast | null {
return currentToast;
}
/**
* Check if buffering toast is active
*/
export function isBufferingActive(): boolean {
return bufferingToastActive;
}
/**
* Show a toast notification
* @param message The message to display
* @param type The type of toast (success, error, info)
* @param type The type of toast (success, error, info, buffering)
* @param duration How long to show the toast in ms (default: varies by type)
*/
export function showToast(message: string, type: ToastType = 'info', duration?: number): void {
@@ -40,22 +51,44 @@ export function showToast(message: string, type: ToastType = 'info', duration?:
hideTimeout = null;
}
// Track buffering state
if (type === 'buffering') {
bufferingToastActive = true;
}
// Set the toast
currentToast = { message, type };
currentToast = {
message,
type,
persistent: type === 'buffering' // Buffering toasts don't auto-hide
};
notifyListeners();
// Auto-hide based on type
const defaultDurations: Record<ToastType, number> = {
success: 3000,
error: 5000,
info: 3000
};
// Auto-hide based on type (buffering is persistent, no timeout)
if (type !== 'buffering') {
const defaultDurations: Record<ToastType, number> = {
success: 3000,
error: 5000,
info: 3000,
buffering: 0 // Never used, but needed for type safety
};
const hideAfter = duration ?? defaultDurations[type];
const hideAfter = duration ?? defaultDurations[type];
hideTimeout = setTimeout(() => {
hideTimeout = setTimeout(() => {
hideToast();
}, hideAfter);
}
}
/**
* Dismiss buffering toast specifically (called when track loads)
*/
export function dismissBuffering(): void {
if (bufferingToastActive) {
bufferingToastActive = false;
hideToast();
}, hideAfter);
}
}
/**