playlist import: add name customization and folder selection
Split import into two-step flow: Fetch (preview) then Import. After fetching, user can edit the playlist name and optionally assign it to a folder before importing. Backend already supported name_override — this just exposes it in the UI. Also i18n all new strings and existing hardcoded modal text.
This commit is contained in:
1 parent
3776925a5f
commit
feb007945b
3 files changed
+197
-27
No files matched your search
@@ -7,6 +7,13 @@
|
|||||||
subscribe as subscribeOffline,
|
subscribe as subscribeOffline,
|
||||||
isOffline as checkIsOffline
|
isOffline as checkIsOffline
|
||||||
} from '$lib/stores/offlineStore';
|
} from '$lib/stores/offlineStore';
|
||||||
|
import {
|
||||||
|
getVisibleFolders,
|
||||||
|
movePlaylistToFolder,
|
||||||
|
loadFolders,
|
||||||
|
subscribe as subscribeFolders
|
||||||
|
} from '$lib/stores/playlistFoldersStore';
|
||||||
|
import type { PlaylistFolder } from '$lib/stores/playlistFoldersStore';
|
||||||
|
|
||||||
type ProviderKey = 'spotify' | 'apple' | 'tidal' | 'deezer';
|
type ProviderKey = 'spotify' | 'apple' | 'tidal' | 'deezer';
|
||||||
|
|
||||||
@@ -51,6 +58,16 @@
|
|||||||
let importCompleted = $state(false);
|
let importCompleted = $state(false);
|
||||||
let lastImportedUrl = $state('');
|
let lastImportedUrl = $state('');
|
||||||
|
|
||||||
|
// Preview + customization state
|
||||||
|
let preview = $state<ImportPlaylist | null>(null);
|
||||||
|
let previewUrl = $state('');
|
||||||
|
let customName = $state('');
|
||||||
|
let selectedFolderId = $state('');
|
||||||
|
let availableFolders = $state<PlaylistFolder[]>([]);
|
||||||
|
|
||||||
|
// Whether to show the preview customization panel
|
||||||
|
const showPreview = $derived(preview !== null && url.trim() === previewUrl);
|
||||||
|
|
||||||
// Subscribe to offline state changes
|
// Subscribe to offline state changes
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
const unsubscribe = subscribeOffline(() => {
|
const unsubscribe = subscribeOffline(() => {
|
||||||
@@ -59,6 +76,15 @@
|
|||||||
return unsubscribe;
|
return unsubscribe;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Load folders and subscribe to changes
|
||||||
|
$effect(() => {
|
||||||
|
loadFolders();
|
||||||
|
const unsubscribe = subscribeFolders(() => {
|
||||||
|
availableFolders = getVisibleFolders();
|
||||||
|
});
|
||||||
|
return unsubscribe;
|
||||||
|
});
|
||||||
|
|
||||||
const providers: { key: ProviderKey; label: string; logo: string; color: string }[] = [
|
const providers: { key: ProviderKey; label: string; logo: string; color: string }[] = [
|
||||||
{ key: 'spotify', label: 'Spotify', logo: '/spotify-logo.svg', color: '#1DB954' },
|
{ key: 'spotify', label: 'Spotify', logo: '/spotify-logo.svg', color: '#1DB954' },
|
||||||
{ key: 'apple', label: 'Apple Music', logo: '/apple-music-logo.svg', color: '#fa233b' },
|
{ key: 'apple', label: 'Apple Music', logo: '/apple-music-logo.svg', color: '#fa233b' },
|
||||||
@@ -80,6 +106,11 @@
|
|||||||
logEntries = [];
|
logEntries = [];
|
||||||
importCompleted = false;
|
importCompleted = false;
|
||||||
lastImportedUrl = '';
|
lastImportedUrl = '';
|
||||||
|
preview = null;
|
||||||
|
previewUrl = '';
|
||||||
|
customName = '';
|
||||||
|
selectedFolderId = '';
|
||||||
|
availableFolders = getVisibleFolders();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -121,7 +152,7 @@
|
|||||||
logEntries = [...logEntries, { message, status }];
|
logEntries = [...logEntries, { message, status }];
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleImport() {
|
async function handlePreview() {
|
||||||
if (!isValid || loading) return;
|
if (!isValid || loading) return;
|
||||||
|
|
||||||
loading = true;
|
loading = true;
|
||||||
@@ -129,26 +160,55 @@
|
|||||||
summary = null;
|
summary = null;
|
||||||
lockedProvider = detectedProvider;
|
lockedProvider = detectedProvider;
|
||||||
logEntries = [];
|
logEntries = [];
|
||||||
|
preview = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
pushLog('Checking playlist link...');
|
pushLog('Checking playlist link...');
|
||||||
const preview = await invoke<ImportPlaylist>('playlist_import_preview', { url });
|
const result = await invoke<ImportPlaylist>('playlist_import_preview', { url });
|
||||||
pushLog(`Found ${preview.tracks.length} tracks from ${formatProvider(preview.provider)}.`);
|
preview = result;
|
||||||
|
previewUrl = url.trim();
|
||||||
|
customName = result.name;
|
||||||
|
pushLog(
|
||||||
|
$t('playlistImport.tracksFound', {
|
||||||
|
values: { count: result.tracks.length, provider: formatProvider(result.provider) }
|
||||||
|
}),
|
||||||
|
'success'
|
||||||
|
);
|
||||||
|
} catch (err) {
|
||||||
|
error = String(err);
|
||||||
|
pushLog(`Import failed: ${error}`, 'error');
|
||||||
|
} finally {
|
||||||
|
loading = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pushLog('Matching tracks in Qobuz™...');
|
async function handleExecute() {
|
||||||
|
if (!preview || loading) return;
|
||||||
|
|
||||||
|
loading = true;
|
||||||
|
error = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
pushLog('Matching tracks in Qobuz\u2122...');
|
||||||
|
const nameOverride = customName.trim() !== preview.name ? customName.trim() || null : null;
|
||||||
const result = await invoke<ImportSummary>('playlist_import_execute', {
|
const result = await invoke<ImportSummary>('playlist_import_execute', {
|
||||||
url,
|
url: previewUrl,
|
||||||
nameOverride: null,
|
nameOverride,
|
||||||
isPublic: false
|
isPublic: false
|
||||||
});
|
});
|
||||||
|
|
||||||
summary = result;
|
summary = result;
|
||||||
importCompleted = true;
|
importCompleted = true;
|
||||||
lastImportedUrl = url.trim();
|
lastImportedUrl = previewUrl;
|
||||||
pushLog(`Imported ${result.matched_tracks} of ${result.total_tracks} tracks into QBZ.`, 'success');
|
pushLog(`Imported ${result.matched_tracks} of ${result.total_tracks} tracks into QBZ.`, 'success');
|
||||||
|
|
||||||
if (result.qobuz_playlist_id) {
|
if (result.qobuz_playlist_id) {
|
||||||
pushLog('Playlist created in Qobuz™.', 'success');
|
pushLog('Playlist created in Qobuz\u2122.', 'success');
|
||||||
|
|
||||||
|
// Move to folder if selected
|
||||||
|
if (selectedFolderId) {
|
||||||
|
await movePlaylistToFolder(result.qobuz_playlist_id, selectedFolderId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
pushLog('No matching tracks found.', 'error');
|
pushLog('No matching tracks found.', 'error');
|
||||||
}
|
}
|
||||||
@@ -185,7 +245,11 @@
|
|||||||
if (e.key === 'Escape') {
|
if (e.key === 'Escape') {
|
||||||
onClose();
|
onClose();
|
||||||
} else if (e.key === 'Enter' && !e.shiftKey) {
|
} else if (e.key === 'Enter' && !e.shiftKey) {
|
||||||
handleImport();
|
if (showPreview && !importCompleted) {
|
||||||
|
handleExecute();
|
||||||
|
} else if (!showPreview) {
|
||||||
|
handlePreview();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
@@ -202,8 +266,8 @@
|
|||||||
<div class="modal" onclick={(e) => e.stopPropagation()}>
|
<div class="modal" onclick={(e) => e.stopPropagation()}>
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
<div class="header-title">
|
<div class="header-title">
|
||||||
<img src="/qobuz-logo.svg" alt="Qobuz™" class="qobuz-logo" />
|
<img src="/qobuz-logo.svg" alt="Qobuz\u2122" class="qobuz-logo" />
|
||||||
<h2>Import Playlist</h2>
|
<h2>{$t('playlistImport.title')}</h2>
|
||||||
</div>
|
</div>
|
||||||
<button class="close-btn" onclick={onClose}>
|
<button class="close-btn" onclick={onClose}>
|
||||||
<X size={20} />
|
<X size={20} />
|
||||||
@@ -223,7 +287,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="playlist-url">Playlist URL</label>
|
<label for="playlist-url">{$t('playlistImport.urlLabel')}</label>
|
||||||
<input
|
<input
|
||||||
id="playlist-url"
|
id="playlist-url"
|
||||||
type="text"
|
type="text"
|
||||||
@@ -234,7 +298,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="sources">
|
<div class="sources">
|
||||||
<span class="sources-label">Allowed sources</span>
|
<span class="sources-label">{$t('playlistImport.allowedSources')}</span>
|
||||||
<div class="sources-logos">
|
<div class="sources-logos">
|
||||||
{#each providers as provider}
|
{#each providers as provider}
|
||||||
<div class="provider" data-provider={provider.key}>
|
<div class="provider" data-provider={provider.key}>
|
||||||
@@ -250,10 +314,40 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if showPreview && preview}
|
||||||
|
<div class="customization">
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="playlist-name">{$t('playlistImport.playlistName')}</label>
|
||||||
|
<input
|
||||||
|
id="playlist-name"
|
||||||
|
type="text"
|
||||||
|
bind:value={customName}
|
||||||
|
disabled={loading || importCompleted}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if availableFolders.length > 0}
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="playlist-folder">{$t('playlistImport.folder')}</label>
|
||||||
|
<select
|
||||||
|
id="playlist-folder"
|
||||||
|
bind:value={selectedFolderId}
|
||||||
|
disabled={loading || importCompleted}
|
||||||
|
>
|
||||||
|
<option value="">{$t('playlistImport.noFolder')}</option>
|
||||||
|
{#each availableFolders as folder}
|
||||||
|
<option value={folder.id}>{folder.name}</option>
|
||||||
|
{/each}
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
{#if logEntries.length > 0}
|
{#if logEntries.length > 0}
|
||||||
<div class="progress-panel">
|
<div class="progress-panel">
|
||||||
<div class="progress-header">
|
<div class="progress-header">
|
||||||
<span>Conversion progress</span>
|
<span>{$t('playlistImport.progress')}</span>
|
||||||
{#if loading}
|
{#if loading}
|
||||||
<span class="spinner" aria-hidden="true"></span>
|
<span class="spinner" aria-hidden="true"></span>
|
||||||
{/if}
|
{/if}
|
||||||
@@ -265,10 +359,10 @@
|
|||||||
</ul>
|
</ul>
|
||||||
{#if summary}
|
{#if summary}
|
||||||
<div class="summary">
|
<div class="summary">
|
||||||
<div class="summary-title">Summary</div>
|
<div class="summary-title">{$t('playlistImport.summary')}</div>
|
||||||
<div class="summary-row">Playlist: {summary.playlist_name}</div>
|
<div class="summary-row">{$t('playlistImport.playlistLabel', { values: { name: summary.playlist_name } })}</div>
|
||||||
<div class="summary-row">Tracks matched: {summary.matched_tracks} / {summary.total_tracks}</div>
|
<div class="summary-row">{$t('playlistImport.tracksMatched', { values: { matched: summary.matched_tracks, total: summary.total_tracks } })}</div>
|
||||||
<div class="summary-row">Skipped: {summary.skipped_tracks}</div>
|
<div class="summary-row">{$t('playlistImport.skipped', { values: { count: summary.skipped_tracks } })}</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
@@ -276,14 +370,26 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button class="btn btn-secondary" onclick={onClose} disabled={loading}>Close</button>
|
<button class="btn btn-secondary" onclick={onClose} disabled={loading}>
|
||||||
<button class="btn btn-primary" onclick={handleImport} disabled={!isValid || loading || importCompleted}>
|
{$t('actions.close')}
|
||||||
{#if loading}
|
|
||||||
Importing...
|
|
||||||
{:else}
|
|
||||||
Import playlist
|
|
||||||
{/if}
|
|
||||||
</button>
|
</button>
|
||||||
|
{#if !showPreview}
|
||||||
|
<button class="btn btn-primary" onclick={handlePreview} disabled={!isValid || loading}>
|
||||||
|
{#if loading}
|
||||||
|
{$t('playlistImport.fetching')}
|
||||||
|
{:else}
|
||||||
|
{$t('playlistImport.fetchPlaylist')}
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{:else}
|
||||||
|
<button class="btn btn-primary" onclick={handleExecute} disabled={loading || importCompleted}>
|
||||||
|
{#if loading}
|
||||||
|
{$t('playlistImport.importing')}
|
||||||
|
{:else}
|
||||||
|
{$t('playlistImport.importAction')}
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -396,7 +502,8 @@
|
|||||||
margin-bottom: 8px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group input[type="text"] {
|
.form-group input[type="text"],
|
||||||
|
.form-group select {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding: 10px 12px;
|
padding: 10px 12px;
|
||||||
background: var(--bg-secondary);
|
background: var(--bg-secondary);
|
||||||
@@ -407,11 +514,38 @@
|
|||||||
transition: border-color 150ms ease;
|
transition: border-color 150ms ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.form-group input[type="text"]:focus {
|
.form-group input[type="text"]:focus,
|
||||||
|
.form-group select:focus {
|
||||||
outline: none;
|
outline: none;
|
||||||
border-color: var(--accent-primary);
|
border-color: var(--accent-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.form-group select {
|
||||||
|
cursor: pointer;
|
||||||
|
appearance: none;
|
||||||
|
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position: right 12px center;
|
||||||
|
padding-right: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.form-group select option {
|
||||||
|
background: var(--bg-secondary);
|
||||||
|
color: var(--text-primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.customization {
|
||||||
|
padding: 16px;
|
||||||
|
border-radius: 12px;
|
||||||
|
background: rgba(0, 0, 0, 0.15);
|
||||||
|
border: 1px solid var(--alpha-8);
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.customization .form-group:last-child {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.sources {
|
.sources {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
@@ -1341,5 +1341,23 @@
|
|||||||
"back": "Back",
|
"back": "Back",
|
||||||
"close": "Close"
|
"close": "Close"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"playlistImport": {
|
||||||
|
"title": "Import Playlist",
|
||||||
|
"urlLabel": "Playlist URL",
|
||||||
|
"allowedSources": "Allowed sources",
|
||||||
|
"playlistName": "Playlist name",
|
||||||
|
"folder": "Folder",
|
||||||
|
"noFolder": "No folder",
|
||||||
|
"fetchPlaylist": "Fetch playlist",
|
||||||
|
"fetching": "Fetching...",
|
||||||
|
"importAction": "Import",
|
||||||
|
"importing": "Importing...",
|
||||||
|
"tracksFound": "Found {count} tracks from {provider}.",
|
||||||
|
"progress": "Conversion progress",
|
||||||
|
"summary": "Summary",
|
||||||
|
"playlistLabel": "Playlist: {name}",
|
||||||
|
"tracksMatched": "Tracks matched: {matched} / {total}",
|
||||||
|
"skipped": "Skipped: {count}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1341,5 +1341,23 @@
|
|||||||
"back": "Atrás",
|
"back": "Atrás",
|
||||||
"close": "Cerrar"
|
"close": "Cerrar"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"playlistImport": {
|
||||||
|
"title": "Importar Playlist",
|
||||||
|
"urlLabel": "URL de la playlist",
|
||||||
|
"allowedSources": "Fuentes permitidas",
|
||||||
|
"playlistName": "Nombre de la playlist",
|
||||||
|
"folder": "Carpeta",
|
||||||
|
"noFolder": "Sin carpeta",
|
||||||
|
"fetchPlaylist": "Obtener playlist",
|
||||||
|
"fetching": "Obteniendo...",
|
||||||
|
"importAction": "Importar",
|
||||||
|
"importing": "Importando...",
|
||||||
|
"tracksFound": "Se encontraron {count} tracks de {provider}.",
|
||||||
|
"progress": "Progreso de conversión",
|
||||||
|
"summary": "Resumen",
|
||||||
|
"playlistLabel": "Playlist: {name}",
|
||||||
|
"tracksMatched": "Tracks encontrados: {matched} / {total}",
|
||||||
|
"skipped": "Omitidos: {count}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user