feat(playlist): track copied playlists and add attribution

- Hide "Copy to My Library" button after playlist has been copied
- Persist copied playlist IDs in localStorage for subsequent visits
- Add attribution note to description: "Originally curated by X on Qobuz"
This commit is contained in:
vicrodh committed 2026-01-25 01:39:32 -06:00
1 parent ee31c3e445
commit dcbe7e802a
2 files changed
+46 -6

No files matched your search

+11 -4
View File
@@ -193,19 +193,26 @@ pub async fn subscribe_playlist(
return Err("Source playlist has no tracks to copy".to_string()); 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 let new_playlist = client
.create_playlist(&source.name, source.description.as_deref(), false) .create_playlist(&source.name, new_description.as_deref(), false)
.await .await
.map_err(|e| format!("Failed to create new playlist: {}", e))?; .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 client
.add_tracks_to_playlist(new_playlist.id, &track_ids) .add_tracks_to_playlist(new_playlist.id, &track_ids)
.await .await
.map_err(|e| format!("Failed to add tracks to new playlist: {}", e))?; .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 { Ok(Playlist {
tracks_count: track_ids.len() as u32, tracks_count: track_ids.len() as u32,
..new_playlist ..new_playlist
@@ -205,6 +205,33 @@
let currentUserId = $state<number | null>(null); let currentUserId = $state<number | null>(null);
let isOwnPlaylist = $derived(playlist !== null && currentUserId !== null && playlist.owner.id === currentUserId); let isOwnPlaylist = $derived(playlist !== null && currentUserId !== null && playlist.owner.id === currentUserId);
let isCopying = $state(false); let isCopying = $state(false);
let isCopied = $state(false);
// Track copied playlists in localStorage
const COPIED_PLAYLISTS_KEY = 'qbz_copied_playlists';
function getCopiedPlaylists(): Set<number> {
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) { async function scrollToTrack(trackId: number) {
await tick(); await tick();
@@ -231,6 +258,11 @@
return unsubscribe; return unsubscribe;
}); });
// Check if this playlist was already copied when playlistId changes
$effect(() => {
isCopied = isPlaylistCopied(playlistId);
});
$effect(() => { $effect(() => {
if (!playlist || displayTracks.length === 0) return; if (!playlist || displayTracks.length === 0) return;
const targetId = consumeContextTrackFocus('playlist', playlist.id.toString()); const targetId = consumeContextTrackFocus('playlist', playlist.id.toString());
@@ -493,9 +525,10 @@
isCopying = true; isCopying = true;
try { try {
const newPlaylist = await invoke<Playlist>('subscribe_playlist', { playlistId: playlist.id }); const newPlaylist = await invoke<Playlist>('subscribe_playlist', { playlistId: playlist.id });
// Mark as copied so button disappears
markPlaylistAsCopied(playlist.id);
// Notify parent to refresh sidebar // Notify parent to refresh sidebar
onPlaylistUpdated?.(); onPlaylistUpdated?.();
// Show success by navigating to the new playlist or show a toast
console.log('Playlist copied successfully:', newPlaylist); console.log('Playlist copied successfully:', newPlaylist);
} catch (err) { } catch (err) {
console.error('Failed to copy playlist:', err); console.error('Failed to copy playlist:', err);
@@ -1047,7 +1080,7 @@
fill={isFavorite ? 'var(--accent-primary)' : 'none'} fill={isFavorite ? 'var(--accent-primary)' : 'none'}
/> />
</button> </button>
{#if !isOwnPlaylist && playlist} {#if showCopyButton}
<button <button
class="action-btn-circle" class="action-btn-circle"
class:is-loading={isCopying} class:is-loading={isCopying}