fix: quality badge accuracy and queue drag-to-reorder
Quality Badge Fix: - Extended BackendQueueTrack with hires, bit_depth, sample_rate fields - Updated all queue track builder functions to pass quality data - Fixed quality badge showing CD instead of Hi-Res for playlist tracks - Extended session persistence to save/restore quality info Queue Drag-to-Reorder: - Added move_track function to Rust QueueManager - Added move_queue_track Tauri command - Implemented HTML5 drag-and-drop in QueuePanel - Visual feedback with drag-over indicator and dragging opacity - Disabled drag when search filter is active - Prevented text selection during drag operations
This commit is contained in:
1 parent
24c8ee5cad
commit
70f03a1003
9 files changed
+256
-18
No files matched your search
@@ -18,6 +18,7 @@
|
||||
onPlayTrack?: (trackId: string) => void;
|
||||
onClearQueue?: () => void;
|
||||
onSaveAsPlaylist?: () => void;
|
||||
onReorderTrack?: (fromIndex: number, toIndex: number) => void;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -27,12 +28,17 @@
|
||||
upcomingTracks,
|
||||
onPlayTrack,
|
||||
onClearQueue,
|
||||
onSaveAsPlaylist
|
||||
onSaveAsPlaylist,
|
||||
onReorderTrack
|
||||
}: Props = $props();
|
||||
|
||||
let hoveredTrack = $state<string | null>(null);
|
||||
let searchQuery = $state('');
|
||||
|
||||
// Drag state
|
||||
let draggedIndex = $state<number | null>(null);
|
||||
let dragOverIndex = $state<number | null>(null);
|
||||
|
||||
// Filter tracks based on search query (searches entire queue)
|
||||
const filteredTracks = $derived.by(() => {
|
||||
if (!searchQuery.trim()) return upcomingTracks;
|
||||
@@ -42,6 +48,62 @@
|
||||
track.artist.toLowerCase().includes(query)
|
||||
);
|
||||
});
|
||||
|
||||
// Disable drag when search is active (can't reorder filtered list)
|
||||
const canDrag = $derived(!searchQuery.trim());
|
||||
|
||||
function handleDragStart(e: DragEvent, index: number) {
|
||||
if (!canDrag) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
draggedIndex = index;
|
||||
// Set drag image and data
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.effectAllowed = 'move';
|
||||
e.dataTransfer.setData('text/plain', String(index));
|
||||
}
|
||||
}
|
||||
|
||||
function handleDragOver(e: DragEvent, index: number) {
|
||||
if (!canDrag || draggedIndex === null) return;
|
||||
e.preventDefault();
|
||||
if (e.dataTransfer) {
|
||||
e.dataTransfer.dropEffect = 'move';
|
||||
}
|
||||
dragOverIndex = index;
|
||||
}
|
||||
|
||||
function handleDragLeave() {
|
||||
dragOverIndex = null;
|
||||
}
|
||||
|
||||
function handleDrop(e: DragEvent, toIndex: number) {
|
||||
e.preventDefault();
|
||||
if (!canDrag || draggedIndex === null || draggedIndex === toIndex) {
|
||||
draggedIndex = null;
|
||||
dragOverIndex = null;
|
||||
return;
|
||||
}
|
||||
onReorderTrack?.(draggedIndex, toIndex);
|
||||
draggedIndex = null;
|
||||
dragOverIndex = null;
|
||||
}
|
||||
|
||||
function handleDragEnd() {
|
||||
draggedIndex = null;
|
||||
dragOverIndex = null;
|
||||
}
|
||||
|
||||
// Handle click only on non-drag-handle area
|
||||
function handleTrackClick(e: MouseEvent, trackId: string) {
|
||||
const target = e.target as HTMLElement;
|
||||
// Don't trigger play if clicking on drag handle
|
||||
if (target.closest('.drag-handle')) {
|
||||
return;
|
||||
}
|
||||
onPlayTrack?.(trackId);
|
||||
}
|
||||
</script>
|
||||
|
||||
{#if isOpen}
|
||||
@@ -104,15 +166,23 @@
|
||||
<div
|
||||
class="queue-track"
|
||||
class:hovered={hoveredTrack === track.id}
|
||||
class:dragging={draggedIndex === originalIndex}
|
||||
class:drag-over={dragOverIndex === originalIndex && draggedIndex !== originalIndex}
|
||||
draggable={canDrag}
|
||||
onmouseenter={() => (hoveredTrack = track.id)}
|
||||
onmouseleave={() => (hoveredTrack = null)}
|
||||
onclick={() => onPlayTrack?.(track.id)}
|
||||
onclick={(e) => handleTrackClick(e, track.id)}
|
||||
ondragstart={(e) => handleDragStart(e, originalIndex)}
|
||||
ondragover={(e) => handleDragOver(e, originalIndex)}
|
||||
ondragleave={handleDragLeave}
|
||||
ondrop={(e) => handleDrop(e, originalIndex)}
|
||||
ondragend={handleDragEnd}
|
||||
role="button"
|
||||
tabindex="0"
|
||||
onkeydown={(e) => e.key === 'Enter' && onPlayTrack?.(track.id)}
|
||||
>
|
||||
<!-- Drag Handle -->
|
||||
<div class="drag-handle" class:visible={hoveredTrack === track.id}>
|
||||
<div class="drag-handle" class:visible={hoveredTrack === track.id && canDrag}>
|
||||
<GripVertical size={14} />
|
||||
</div>
|
||||
|
||||
@@ -382,10 +452,30 @@
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.queue-track.dragging {
|
||||
opacity: 0.5;
|
||||
background-color: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.queue-track.drag-over {
|
||||
border-top: 2px solid var(--accent-primary);
|
||||
margin-top: -2px;
|
||||
}
|
||||
|
||||
.queue-track[draggable="true"] {
|
||||
user-select: none;
|
||||
-webkit-user-select: none;
|
||||
}
|
||||
|
||||
.drag-handle {
|
||||
color: #666666;
|
||||
opacity: 0;
|
||||
transition: opacity 150ms ease;
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.drag-handle:active {
|
||||
cursor: grabbing;
|
||||
}
|
||||
|
||||
.drag-handle.visible {
|
||||
|
||||
@@ -14,6 +14,9 @@ export interface PersistedQueueTrack {
|
||||
album: string;
|
||||
duration_secs: number;
|
||||
artwork_url: string | null;
|
||||
hires?: boolean;
|
||||
bit_depth?: number | null;
|
||||
sample_rate?: number | null;
|
||||
}
|
||||
|
||||
export interface PersistedSession {
|
||||
|
||||
@@ -40,7 +40,10 @@ export function buildQueueTrackFromQobuz(track: QobuzTrack): BackendQueueTrack {
|
||||
artist: track.performer?.name || 'Unknown Artist',
|
||||
album: track.album?.title || '',
|
||||
duration_secs: track.duration,
|
||||
artwork_url: artwork || null
|
||||
artwork_url: artwork || null,
|
||||
hires: track.hires_streamable ?? false,
|
||||
bit_depth: track.maximum_bit_depth ?? null,
|
||||
sample_rate: track.maximum_sampling_rate ?? null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -51,7 +54,10 @@ export function buildQueueTrackFromAlbumTrack(track: Track, albumArtwork: string
|
||||
artist: track.artist || albumArtist || 'Unknown Artist',
|
||||
album: albumTitle || '',
|
||||
duration_secs: track.durationSeconds,
|
||||
artwork_url: albumArtwork || null
|
||||
artwork_url: albumArtwork || null,
|
||||
hires: track.hires ?? false,
|
||||
bit_depth: track.bitDepth ?? null,
|
||||
sample_rate: track.samplingRate ?? null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -62,19 +68,27 @@ export function buildQueueTrackFromPlaylistTrack(track: PlaylistTrack): BackendQ
|
||||
artist: track.artist || 'Unknown Artist',
|
||||
album: track.album || 'Playlist',
|
||||
duration_secs: track.durationSeconds,
|
||||
artwork_url: track.albumArt || null
|
||||
artwork_url: track.albumArt || null,
|
||||
hires: track.hires ?? false,
|
||||
bit_depth: track.bitDepth ?? null,
|
||||
sample_rate: track.samplingRate ?? null
|
||||
};
|
||||
}
|
||||
|
||||
export function buildQueueTrackFromLocalTrack(track: LocalLibraryTrack): BackendQueueTrack {
|
||||
const artwork = track.artwork_path ? `asset://localhost/${encodeURIComponent(track.artwork_path)}` : null;
|
||||
// Local tracks are hi-res if bit_depth > 16 or sample_rate > 44100
|
||||
const isHires = Boolean((track.bit_depth && track.bit_depth > 16) || (track.sample_rate && track.sample_rate > 44100));
|
||||
return {
|
||||
id: track.id,
|
||||
title: track.title,
|
||||
artist: track.artist,
|
||||
album: track.album,
|
||||
duration_secs: track.duration_secs,
|
||||
artwork_url: artwork
|
||||
artwork_url: artwork,
|
||||
hires: isHires,
|
||||
bit_depth: track.bit_depth ?? null,
|
||||
sample_rate: track.sample_rate ?? null
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ export interface BackendQueueTrack {
|
||||
album: string;
|
||||
duration_secs: number;
|
||||
artwork_url: string | null;
|
||||
hires: boolean;
|
||||
bit_depth: number | null;
|
||||
sample_rate: number | null;
|
||||
}
|
||||
|
||||
interface BackendQueueState {
|
||||
@@ -294,6 +297,22 @@ export async function previousTrack(): Promise<BackendQueueTrack | null> {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a track from one position to another in the queue
|
||||
*/
|
||||
export async function moveQueueTrack(fromIndex: number, toIndex: number): Promise<boolean> {
|
||||
try {
|
||||
const success = await invoke<boolean>('move_queue_track', { fromIndex, toIndex });
|
||||
if (success) {
|
||||
await syncQueueState();
|
||||
}
|
||||
return success;
|
||||
} catch (err) {
|
||||
console.error('Failed to move queue track:', err);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// ============ Local Track Management ============
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user