fix(playlists): add local tracks to playlists correctly
- PlaylistModal now uses playlist_add_local_track command for local tracks instead of the Qobuz-only add_tracks_to_playlist command - Added isLocalTracks prop to PlaylistModal and wired it through uiStore - Updated LocalLibraryView to pass isLocal=true when adding tracks to playlists - Added HardDrive icon indicator next to quality badge for local tracks in TrackRow cc
This commit is contained in:
1 parent
81d2bdcf33
commit
3915abd3bb
5 files changed
+155
-50
No files matched your search
@@ -19,6 +19,7 @@
|
||||
onSuccess?: (playlist?: Playlist) => void;
|
||||
onDelete?: (playlistId: number) => void;
|
||||
isHidden?: boolean;
|
||||
isLocalTracks?: boolean;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -30,7 +31,8 @@
|
||||
onClose,
|
||||
onSuccess,
|
||||
onDelete,
|
||||
isHidden = false
|
||||
isHidden = false,
|
||||
isLocalTracks = false
|
||||
}: Props = $props();
|
||||
|
||||
// Form state
|
||||
@@ -154,11 +156,22 @@
|
||||
error = null;
|
||||
|
||||
try {
|
||||
await invoke('add_tracks_to_playlist', {
|
||||
playlistId: selectedPlaylistId,
|
||||
trackIds
|
||||
});
|
||||
void logPlaylistAdd(trackIds, selectedPlaylistId);
|
||||
if (isLocalTracks) {
|
||||
// Add local tracks one by one
|
||||
for (let i = 0; i < trackIds.length; i++) {
|
||||
await invoke('playlist_add_local_track', {
|
||||
playlistId: selectedPlaylistId,
|
||||
localTrackId: trackIds[i],
|
||||
position: i
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await invoke('add_tracks_to_playlist', {
|
||||
playlistId: selectedPlaylistId,
|
||||
trackIds
|
||||
});
|
||||
void logPlaylistAdd(trackIds, selectedPlaylistId);
|
||||
}
|
||||
onSuccess?.();
|
||||
onClose();
|
||||
} catch (err) {
|
||||
@@ -188,11 +201,22 @@
|
||||
|
||||
// Then add tracks
|
||||
if (trackIds.length > 0) {
|
||||
await invoke('add_tracks_to_playlist', {
|
||||
playlistId: newPlaylist.id,
|
||||
trackIds
|
||||
});
|
||||
void logPlaylistAdd(trackIds, newPlaylist.id);
|
||||
if (isLocalTracks) {
|
||||
// Add local tracks one by one
|
||||
for (let i = 0; i < trackIds.length; i++) {
|
||||
await invoke('playlist_add_local_track', {
|
||||
playlistId: newPlaylist.id,
|
||||
localTrackId: trackIds[i],
|
||||
position: i
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await invoke('add_tracks_to_playlist', {
|
||||
playlistId: newPlaylist.id,
|
||||
trackIds
|
||||
});
|
||||
void logPlaylistAdd(trackIds, newPlaylist.id);
|
||||
}
|
||||
}
|
||||
|
||||
onSuccess?.(newPlaylist);
|
||||
@@ -261,7 +285,7 @@
|
||||
|
||||
{#if mode === 'addTrack'}
|
||||
<div class="track-info">
|
||||
Adding {trackIds.length} track{trackIds.length !== 1 ? 's' : ''}
|
||||
Adding {trackIds.length} {isLocalTracks ? 'local ' : ''}track{trackIds.length !== 1 ? 's' : ''}
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { Play, Heart } from 'lucide-svelte';
|
||||
import { Play, Heart, HardDrive } from 'lucide-svelte';
|
||||
import TrackMenu from './TrackMenu.svelte';
|
||||
import DownloadButton from './DownloadButton.svelte';
|
||||
import {
|
||||
@@ -20,6 +20,7 @@
|
||||
duration: string;
|
||||
quality?: string;
|
||||
isPlaying?: boolean;
|
||||
isLocal?: boolean; // Whether this is a local library track
|
||||
isFavoriteOverride?: boolean; // Optional override for favorite state
|
||||
downloadStatus?: DownloadStatus;
|
||||
downloadProgress?: number;
|
||||
@@ -54,6 +55,7 @@
|
||||
duration,
|
||||
quality,
|
||||
isPlaying = false,
|
||||
isLocal = false,
|
||||
isFavoriteOverride,
|
||||
downloadStatus = 'none',
|
||||
downloadProgress = 0,
|
||||
@@ -174,7 +176,14 @@
|
||||
<div class="track-duration">{duration}</div>
|
||||
|
||||
<!-- Quality (always render to maintain column alignment) -->
|
||||
<div class="track-quality">{quality ?? ''}</div>
|
||||
<div class="track-quality">
|
||||
{#if isLocal}
|
||||
<span class="local-icon" title="Local library track">
|
||||
<HardDrive size={12} />
|
||||
</span>
|
||||
{/if}
|
||||
{quality ?? ''}
|
||||
</div>
|
||||
|
||||
<!-- Favorite Button -->
|
||||
{#if !hideFavorite}
|
||||
@@ -382,12 +391,23 @@
|
||||
}
|
||||
|
||||
.track-quality {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 4px;
|
||||
font-size: 12px;
|
||||
color: #666666;
|
||||
width: 80px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.local-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: var(--text-muted);
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.favorite-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invoke, convertFileSrc } from '@tauri-apps/api/core';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import { open, ask } from '@tauri-apps/plugin-dialog';
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import {
|
||||
HardDrive, Music, Disc3, Mic2, FolderPlus, Trash2, RefreshCw,
|
||||
@@ -534,27 +534,38 @@
|
||||
|
||||
let clearingLibrary = $state(false);
|
||||
|
||||
function handleClearLibrary(event: MouseEvent) {
|
||||
// Prevent double execution
|
||||
async function handleClearLibrary(event: MouseEvent) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
|
||||
if (clearingLibrary) return;
|
||||
|
||||
const firstConfirm = confirm(
|
||||
'Clear entire library?\n\n' +
|
||||
// First confirmation using Tauri dialog (async, properly sequential)
|
||||
const firstConfirm = await ask(
|
||||
'This will remove ALL indexed tracks from the database.\n' +
|
||||
'Your audio files will NOT be deleted.\n\n' +
|
||||
'You will need to re-scan your folders after this.'
|
||||
'You will need to re-scan your folders after this.',
|
||||
{
|
||||
title: 'Clear entire library?',
|
||||
kind: 'warning',
|
||||
okLabel: 'Continue',
|
||||
cancelLabel: 'Cancel'
|
||||
}
|
||||
);
|
||||
|
||||
if (!firstConfirm) {
|
||||
return;
|
||||
}
|
||||
|
||||
const secondConfirm = confirm(
|
||||
'Are you absolutely sure?\n\n' +
|
||||
'This action cannot be undone.'
|
||||
// Second confirmation - only shown after first is confirmed
|
||||
const secondConfirm = await ask(
|
||||
'This action cannot be undone.',
|
||||
{
|
||||
title: 'Are you absolutely sure?',
|
||||
kind: 'warning',
|
||||
okLabel: 'Clear Library',
|
||||
cancelLabel: 'Cancel'
|
||||
}
|
||||
);
|
||||
|
||||
if (!secondConfirm) {
|
||||
@@ -564,20 +575,18 @@
|
||||
// Only proceed if both confirmations passed
|
||||
clearingLibrary = true;
|
||||
|
||||
invoke('library_clear')
|
||||
.then(() => loadLibraryData())
|
||||
.then(() => {
|
||||
albums = [];
|
||||
artists = [];
|
||||
tracks = [];
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error('Failed to clear library:', err);
|
||||
alert(`Failed to clear library: ${err}`);
|
||||
})
|
||||
.finally(() => {
|
||||
clearingLibrary = false;
|
||||
});
|
||||
try {
|
||||
await invoke('library_clear');
|
||||
await loadLibraryData();
|
||||
albums = [];
|
||||
artists = [];
|
||||
tracks = [];
|
||||
} catch (err) {
|
||||
console.error('Failed to clear library:', err);
|
||||
alert(`Failed to clear library: ${err}`);
|
||||
} finally {
|
||||
clearingLibrary = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFetchMissingArtwork() {
|
||||
@@ -1379,15 +1388,6 @@
|
||||
<Play size={16} fill="white" />
|
||||
<span>Play All</span>
|
||||
</button>
|
||||
<button
|
||||
class="secondary-btn"
|
||||
onclick={handleSetAlbumArtwork}
|
||||
disabled={updatingArtwork}
|
||||
title="Set album artwork"
|
||||
>
|
||||
<Upload size={14} />
|
||||
<span>{updatingArtwork ? 'Updating...' : 'Set Cover'}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1404,6 +1404,7 @@
|
||||
artist={track.artist !== selectedAlbum?.artist ? track.artist : undefined}
|
||||
duration={formatDuration(track.duration_secs)}
|
||||
quality={getQualityBadge(track)}
|
||||
isLocal={true}
|
||||
hideDownload={true}
|
||||
hideFavorite={true}
|
||||
onArtistClick={track.artist && track.artist !== selectedAlbum?.artist
|
||||
@@ -2043,6 +2044,7 @@
|
||||
artist={track.artist}
|
||||
duration={formatDuration(track.duration_secs)}
|
||||
quality={getQualityBadge(track)}
|
||||
isLocal={true}
|
||||
hideDownload={true}
|
||||
hideFavorite={true}
|
||||
onArtistClick={track.artist ? () => handleLocalArtistClick(track.artist) : undefined}
|
||||
@@ -2065,6 +2067,7 @@
|
||||
artist={track.artist}
|
||||
duration={formatDuration(track.duration_secs)}
|
||||
quality={getQualityBadge(track)}
|
||||
isLocal={true}
|
||||
hideDownload={true}
|
||||
hideFavorite={true}
|
||||
onArtistClick={track.artist ? () => handleLocalArtistClick(track.artist) : undefined}
|
||||
@@ -2131,6 +2134,31 @@
|
||||
<p class="form-hint">Album title editing coming soon</p>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Album Artwork</label>
|
||||
<div class="artwork-row">
|
||||
{#if selectedAlbum.artwork_path}
|
||||
<img
|
||||
src={getArtworkUrl(selectedAlbum.artwork_path)}
|
||||
alt="Current artwork"
|
||||
class="artwork-preview"
|
||||
/>
|
||||
{:else}
|
||||
<div class="artwork-preview artwork-placeholder-mini">
|
||||
<Disc3 size={24} />
|
||||
</div>
|
||||
{/if}
|
||||
<button
|
||||
class="secondary-btn"
|
||||
onclick={handleSetAlbumArtwork}
|
||||
disabled={updatingArtwork}
|
||||
>
|
||||
<Upload size={14} />
|
||||
<span>{updatingArtwork ? 'Updating...' : 'Change Cover'}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label class="toggle-label">
|
||||
<input
|
||||
@@ -3445,6 +3473,27 @@
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.artwork-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.artwork-preview {
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border-radius: 6px;
|
||||
object-fit: cover;
|
||||
background: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.artwork-placeholder-mini {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.modal-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
Reference in new issue
Block a user