diff --git a/src-tauri/src/commands/playlist.rs b/src-tauri/src/commands/playlist.rs index 69794242b..8adcec877 100644 --- a/src-tauri/src/commands/playlist.rs +++ b/src-tauri/src/commands/playlist.rs @@ -193,19 +193,26 @@ pub async fn subscribe_playlist( return Err("Source playlist has no tracks to copy".to_string()); } - // 3. Create a new playlist with the same name + // 3. Build description with attribution + let attribution = format!("\n\n---\nOriginally curated by {} on Qobuz", source.owner.name); + let new_description = match source.description { + Some(ref desc) if !desc.is_empty() => Some(format!("{}{}", desc, attribution)), + _ => Some(attribution.trim_start().to_string()), + }; + + // 4. Create a new playlist with the same name and attributed description let new_playlist = client - .create_playlist(&source.name, source.description.as_deref(), false) + .create_playlist(&source.name, new_description.as_deref(), false) .await .map_err(|e| format!("Failed to create new playlist: {}", e))?; - // 4. Add all tracks to the new playlist + // 5. Add all tracks to the new playlist client .add_tracks_to_playlist(new_playlist.id, &track_ids) .await .map_err(|e| format!("Failed to add tracks to new playlist: {}", e))?; - // 5. Return the new playlist with updated track count + // 6. Return the new playlist with updated track count Ok(Playlist { tracks_count: track_ids.len() as u32, ..new_playlist diff --git a/src/lib/components/views/PlaylistDetailView.svelte b/src/lib/components/views/PlaylistDetailView.svelte index 3ef1a2f09..e966bfb0e 100644 --- a/src/lib/components/views/PlaylistDetailView.svelte +++ b/src/lib/components/views/PlaylistDetailView.svelte @@ -205,6 +205,33 @@ let currentUserId = $state(null); let isOwnPlaylist = $derived(playlist !== null && currentUserId !== null && playlist.owner.id === currentUserId); let isCopying = $state(false); + let isCopied = $state(false); + + // Track copied playlists in localStorage + const COPIED_PLAYLISTS_KEY = 'qbz_copied_playlists'; + + function getCopiedPlaylists(): Set { + try { + const stored = localStorage.getItem(COPIED_PLAYLISTS_KEY); + return stored ? new Set(JSON.parse(stored)) : new Set(); + } catch { + return new Set(); + } + } + + function markPlaylistAsCopied(id: number) { + const copied = getCopiedPlaylists(); + copied.add(id); + localStorage.setItem(COPIED_PLAYLISTS_KEY, JSON.stringify([...copied])); + isCopied = true; + } + + function isPlaylistCopied(id: number): boolean { + return getCopiedPlaylists().has(id); + } + + // Show copy button only if: not own playlist AND not already copied + let showCopyButton = $derived(!isOwnPlaylist && playlist !== null && !isCopied); async function scrollToTrack(trackId: number) { await tick(); @@ -231,6 +258,11 @@ return unsubscribe; }); + // Check if this playlist was already copied when playlistId changes + $effect(() => { + isCopied = isPlaylistCopied(playlistId); + }); + $effect(() => { if (!playlist || displayTracks.length === 0) return; const targetId = consumeContextTrackFocus('playlist', playlist.id.toString()); @@ -493,9 +525,10 @@ isCopying = true; try { const newPlaylist = await invoke('subscribe_playlist', { playlistId: playlist.id }); + // Mark as copied so button disappears + markPlaylistAsCopied(playlist.id); // Notify parent to refresh sidebar onPlaylistUpdated?.(); - // Show success by navigating to the new playlist or show a toast console.log('Playlist copied successfully:', newPlaylist); } catch (err) { console.error('Failed to copy playlist:', err); @@ -1047,7 +1080,7 @@ fill={isFavorite ? 'var(--accent-primary)' : 'none'} /> - {#if !isOwnPlaylist && playlist} + {#if showCopyButton}