From feb007945bbc6ada43441922967f650c3e3d304c Mon Sep 17 00:00:00 2001 From: vicrodh <103399283+vicrodh@users.noreply.github.com> Date: Fri, 6 Feb 2026 23:38:08 -0600 Subject: [PATCH] playlist import: add name customization and folder selection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/lib/components/PlaylistImportModal.svelte | 188 +++++++++++++++--- src/lib/i18n/locales/en.json | 18 ++ src/lib/i18n/locales/es.json | 18 ++ 3 files changed, 197 insertions(+), 27 deletions(-) diff --git a/src/lib/components/PlaylistImportModal.svelte b/src/lib/components/PlaylistImportModal.svelte index a29fae5ff..5ff5565e5 100644 --- a/src/lib/components/PlaylistImportModal.svelte +++ b/src/lib/components/PlaylistImportModal.svelte @@ -7,6 +7,13 @@ subscribe as subscribeOffline, isOffline as checkIsOffline } 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'; @@ -51,6 +58,16 @@ let importCompleted = $state(false); let lastImportedUrl = $state(''); + // Preview + customization state + let preview = $state(null); + let previewUrl = $state(''); + let customName = $state(''); + let selectedFolderId = $state(''); + let availableFolders = $state([]); + + // Whether to show the preview customization panel + const showPreview = $derived(preview !== null && url.trim() === previewUrl); + // Subscribe to offline state changes $effect(() => { const unsubscribe = subscribeOffline(() => { @@ -59,6 +76,15 @@ 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 }[] = [ { key: 'spotify', label: 'Spotify', logo: '/spotify-logo.svg', color: '#1DB954' }, { key: 'apple', label: 'Apple Music', logo: '/apple-music-logo.svg', color: '#fa233b' }, @@ -80,6 +106,11 @@ logEntries = []; importCompleted = false; lastImportedUrl = ''; + preview = null; + previewUrl = ''; + customName = ''; + selectedFolderId = ''; + availableFolders = getVisibleFolders(); } }); @@ -121,7 +152,7 @@ logEntries = [...logEntries, { message, status }]; } - async function handleImport() { + async function handlePreview() { if (!isValid || loading) return; loading = true; @@ -129,26 +160,55 @@ summary = null; lockedProvider = detectedProvider; logEntries = []; + preview = null; try { pushLog('Checking playlist link...'); - const preview = await invoke('playlist_import_preview', { url }); - pushLog(`Found ${preview.tracks.length} tracks from ${formatProvider(preview.provider)}.`); + const result = await invoke('playlist_import_preview', { url }); + 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('playlist_import_execute', { - url, - nameOverride: null, + url: previewUrl, + nameOverride, isPublic: false }); summary = result; importCompleted = true; - lastImportedUrl = url.trim(); + lastImportedUrl = previewUrl; pushLog(`Imported ${result.matched_tracks} of ${result.total_tracks} tracks into QBZ.`, 'success'); 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 { pushLog('No matching tracks found.', 'error'); } @@ -185,7 +245,11 @@ if (e.key === 'Escape') { onClose(); } else if (e.key === 'Enter' && !e.shiftKey) { - handleImport(); + if (showPreview && !importCompleted) { + handleExecute(); + } else if (!showPreview) { + handlePreview(); + } } } @@ -202,8 +266,8 @@ @@ -396,7 +502,8 @@ margin-bottom: 8px; } - .form-group input[type="text"] { + .form-group input[type="text"], + .form-group select { width: 100%; padding: 10px 12px; background: var(--bg-secondary); @@ -407,11 +514,38 @@ transition: border-color 150ms ease; } - .form-group input[type="text"]:focus { + .form-group input[type="text"]:focus, + .form-group select:focus { outline: none; 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 { display: flex; flex-direction: column; diff --git a/src/lib/i18n/locales/en.json b/src/lib/i18n/locales/en.json index 55a7da3df..8cd8e642c 100644 --- a/src/lib/i18n/locales/en.json +++ b/src/lib/i18n/locales/en.json @@ -1341,5 +1341,23 @@ "back": "Back", "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}" } } diff --git a/src/lib/i18n/locales/es.json b/src/lib/i18n/locales/es.json index 919ee0d6d..020d5c9b7 100644 --- a/src/lib/i18n/locales/es.json +++ b/src/lib/i18n/locales/es.json @@ -1341,5 +1341,23 @@ "back": "Atrás", "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}" } }