feat(playlist): add ability to copy Qobuz playlists to user library
When viewing a playlist not owned by the current user, a new "Copy to My Library" button appears between the favorite and context menu buttons. Clicking it creates a copy of the playlist with all its tracks in the user's library. - Add get_current_user_id command to check playlist ownership - Add subscribe_playlist command to copy playlist with all tracks - Add ListPlus button in PlaylistDetailView for non-owned playlists - Button only shows for playlists owned by others (e.g., Qobuz curated)
This commit is contained in:
1 parent
a276a30ff2
commit
ee31c3e445
4 files changed
+105
-2
No files matched your search
@@ -1,5 +1,5 @@
|
||||
<script lang="ts">
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ChevronRight, ImagePlus, Edit3, BarChart2, Heart, CloudDownload } from 'lucide-svelte';
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ChevronRight, ImagePlus, Edit3, BarChart2, Heart, CloudDownload, ListPlus } from 'lucide-svelte';
|
||||
import AlbumMenu from '../AlbumMenu.svelte';
|
||||
import PlaylistCollage from '../PlaylistCollage.svelte';
|
||||
import PlaylistModal from '../PlaylistModal.svelte';
|
||||
@@ -201,14 +201,26 @@
|
||||
let editModalOpen = $state(false);
|
||||
let isFavorite = $state(false);
|
||||
|
||||
// User ownership state (to show "Copy to Library" button for non-owned playlists)
|
||||
let currentUserId = $state<number | null>(null);
|
||||
let isOwnPlaylist = $derived(playlist !== null && currentUserId !== null && playlist.owner.id === currentUserId);
|
||||
let isCopying = $state(false);
|
||||
|
||||
async function scrollToTrack(trackId: number) {
|
||||
await tick();
|
||||
const target = scrollContainer?.querySelector<HTMLElement>(`[data-track-id="${trackId}"]`);
|
||||
target?.scrollIntoView({ block: 'center' });
|
||||
}
|
||||
|
||||
// Subscribe to offline status changes
|
||||
// Subscribe to offline status changes and fetch current user ID
|
||||
onMount(() => {
|
||||
// Fetch current user ID for ownership check
|
||||
invoke<number | null>('get_current_user_id').then(userId => {
|
||||
currentUserId = userId;
|
||||
}).catch(err => {
|
||||
console.warn('Failed to get current user ID:', err);
|
||||
});
|
||||
|
||||
const unsubscribe = subscribeOffline(() => {
|
||||
offlineStatus = getOfflineStatus();
|
||||
// Re-check local copies when offline status changes
|
||||
@@ -475,6 +487,23 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function copyPlaylistToLibrary() {
|
||||
if (isCopying || !playlist) return;
|
||||
|
||||
isCopying = true;
|
||||
try {
|
||||
const newPlaylist = await invoke<Playlist>('subscribe_playlist', { playlistId: 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);
|
||||
} finally {
|
||||
isCopying = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveSort(field: SortField, order: SortOrder) {
|
||||
sortBy = field;
|
||||
sortOrder = order;
|
||||
@@ -1018,6 +1047,17 @@
|
||||
fill={isFavorite ? 'var(--accent-primary)' : 'none'}
|
||||
/>
|
||||
</button>
|
||||
{#if !isOwnPlaylist && playlist}
|
||||
<button
|
||||
class="action-btn-circle"
|
||||
class:is-loading={isCopying}
|
||||
onclick={copyPlaylistToLibrary}
|
||||
disabled={isCopying}
|
||||
title="Copy to My Library"
|
||||
>
|
||||
<ListPlus size={18} />
|
||||
</button>
|
||||
{/if}
|
||||
<AlbumMenu
|
||||
onPlayNext={handlePlayAllNext}
|
||||
onPlayLater={handlePlayAllLater}
|
||||
|
||||
Reference in new issue
Block a user