feat(playlists): Add hidden toggle and delete to PlaylistModal
- Add hidden checkbox to toggle sidebar visibility in edit mode - Add danger zone with delete button and confirmation - Update handleUpdate to save hidden status locally - Add handleDelete function with proper error handling - Style danger zone with red theme for visibility
This commit is contained in:
1 parent
3fb9ee1381
commit
ec4df03455
1 file changed
+183
-2
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { X } from 'lucide-svelte';
|
||||
import { X, Trash2, EyeOff, Eye } from 'lucide-svelte';
|
||||
import { logPlaylistAdd } from '$lib/services/recoService';
|
||||
import GlassSurface from './glass/GlassSurface.svelte';
|
||||
|
||||
@@ -18,6 +18,8 @@
|
||||
userPlaylists?: Playlist[];
|
||||
onClose: () => void;
|
||||
onSuccess?: (playlist?: Playlist) => void;
|
||||
onDelete?: (playlistId: number) => void;
|
||||
isHidden?: boolean;
|
||||
}
|
||||
|
||||
let {
|
||||
@@ -27,30 +29,37 @@
|
||||
trackIds = [],
|
||||
userPlaylists = [],
|
||||
onClose,
|
||||
onSuccess
|
||||
onSuccess,
|
||||
onDelete,
|
||||
isHidden = false
|
||||
}: Props = $props();
|
||||
|
||||
// Form state
|
||||
let name = $state('');
|
||||
let description = $state('');
|
||||
let isPublic = $state(false);
|
||||
let hidden = $state(false);
|
||||
let selectedPlaylistId = $state<number | null>(null);
|
||||
let loading = $state(false);
|
||||
let error = $state<string | null>(null);
|
||||
let showDeleteConfirm = $state(false);
|
||||
|
||||
// Reset form when modal opens
|
||||
$effect(() => {
|
||||
if (isOpen) {
|
||||
error = null;
|
||||
loading = false;
|
||||
showDeleteConfirm = false;
|
||||
if (mode === 'edit' && playlist) {
|
||||
name = playlist.name;
|
||||
description = '';
|
||||
isPublic = false;
|
||||
hidden = isHidden;
|
||||
} else if (mode === 'create') {
|
||||
name = '';
|
||||
description = '';
|
||||
isPublic = false;
|
||||
hidden = false;
|
||||
} else if (mode === 'addTrack') {
|
||||
selectedPlaylistId = null;
|
||||
}
|
||||
@@ -93,12 +102,20 @@
|
||||
error = null;
|
||||
|
||||
try {
|
||||
// Update playlist on Qobuz
|
||||
const updatedPlaylist = await invoke<Playlist>('update_playlist', {
|
||||
playlistId: playlist.id,
|
||||
name: name.trim(),
|
||||
description: description.trim() || null,
|
||||
isPublic
|
||||
});
|
||||
|
||||
// Update hidden status locally
|
||||
await invoke('playlist_set_hidden', {
|
||||
playlistId: playlist.id,
|
||||
hidden
|
||||
});
|
||||
|
||||
onSuccess?.(updatedPlaylist);
|
||||
onClose();
|
||||
} catch (err) {
|
||||
@@ -109,6 +126,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleDelete() {
|
||||
if (!playlist) return;
|
||||
|
||||
loading = true;
|
||||
error = null;
|
||||
|
||||
try {
|
||||
await invoke('delete_playlist', { playlistId: playlist.id });
|
||||
onDelete?.(playlist.id);
|
||||
onClose();
|
||||
} catch (err) {
|
||||
console.error('Failed to delete playlist:', err);
|
||||
error = String(err);
|
||||
showDeleteConfirm = false;
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAddToPlaylist() {
|
||||
if (!selectedPlaylistId || trackIds.length === 0) {
|
||||
error = 'Please select a playlist';
|
||||
@@ -289,6 +325,48 @@
|
||||
<span>Make playlist public</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
{#if mode === 'edit'}
|
||||
<div class="form-group checkbox">
|
||||
<label>
|
||||
<input
|
||||
type="checkbox"
|
||||
bind:checked={hidden}
|
||||
disabled={loading}
|
||||
/>
|
||||
<span class="hidden-label">
|
||||
{#if hidden}
|
||||
<EyeOff size={14} />
|
||||
{:else}
|
||||
<Eye size={14} />
|
||||
{/if}
|
||||
Hide from sidebar
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<div class="danger-zone">
|
||||
<div class="danger-label">Danger Zone</div>
|
||||
{#if showDeleteConfirm}
|
||||
<div class="delete-confirm">
|
||||
<span>Are you sure? This cannot be undone.</span>
|
||||
<div class="delete-actions">
|
||||
<button class="btn-cancel" onclick={() => showDeleteConfirm = false} disabled={loading}>
|
||||
Cancel
|
||||
</button>
|
||||
<button class="btn-delete" onclick={handleDelete} disabled={loading}>
|
||||
{loading ? 'Deleting...' : 'Delete'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<button class="btn-danger" onclick={() => showDeleteConfirm = true} disabled={loading}>
|
||||
<Trash2 size={14} />
|
||||
Delete Playlist
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -504,4 +582,107 @@
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.hidden-label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.danger-zone {
|
||||
margin-top: 24px;
|
||||
padding-top: 20px;
|
||||
border-top: 1px solid rgba(239, 68, 68, 0.2);
|
||||
}
|
||||
|
||||
.danger-label {
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: #ef4444;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.btn-danger {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 10px 16px;
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.3);
|
||||
border-radius: 8px;
|
||||
font-size: 13px;
|
||||
color: #ef4444;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.btn-danger:hover:not(:disabled) {
|
||||
background: rgba(239, 68, 68, 0.2);
|
||||
border-color: rgba(239, 68, 68, 0.5);
|
||||
}
|
||||
|
||||
.btn-danger:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.delete-confirm {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 12px;
|
||||
padding: 12px;
|
||||
background: rgba(239, 68, 68, 0.1);
|
||||
border: 1px solid rgba(239, 68, 68, 0.3);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.delete-confirm span {
|
||||
font-size: 13px;
|
||||
color: #ef4444;
|
||||
}
|
||||
|
||||
.delete-actions {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.btn-cancel {
|
||||
flex: 1;
|
||||
padding: 8px 12px;
|
||||
background: var(--bg-tertiary);
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: var(--text-primary);
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.btn-cancel:hover:not(:disabled) {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.btn-delete {
|
||||
flex: 1;
|
||||
padding: 8px 12px;
|
||||
background: #ef4444;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-size: 13px;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.btn-delete:hover:not(:disabled) {
|
||||
background: #dc2626;
|
||||
}
|
||||
|
||||
.btn-cancel:disabled,
|
||||
.btn-delete:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user