feat(phase4.3): add favorites edit modal component
- Create FavoritesEditModal with preset icon grid - Add custom image upload button - Add tab reorder UI with up/down buttons - Integrate edit button in Favorites page header (top-right) - Add i18n keys for EN and ES - Wire modal save handler to backend cc
This commit is contained in:
1 parent
a6aa6aa936
commit
5bd52cc89b
5 files changed
+476
-3
No files matched your search
@@ -0,0 +1,368 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import Modal from './Modal.svelte';
|
||||
import { Heart, Star, Music, Folder, Disc, Library, Upload, GripVertical } from 'lucide-svelte';
|
||||
import type { FavoritesPreferences } from '../types';
|
||||
|
||||
interface Props {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
onSave: (prefs: FavoritesPreferences) => void;
|
||||
initialPreferences: FavoritesPreferences;
|
||||
}
|
||||
|
||||
let { isOpen, onClose, onSave, initialPreferences }: Props = $props();
|
||||
|
||||
let customIconPath = $state<string | null>(initialPreferences.custom_icon_path || null);
|
||||
let customIconPreset = $state<string | null>(initialPreferences.custom_icon_preset || 'heart');
|
||||
let tabOrder = $state<string[]>([...initialPreferences.tab_order]);
|
||||
let useCustomImage = $state(!!initialPreferences.custom_icon_path);
|
||||
let saving = $state(false);
|
||||
|
||||
const presetIcons = [
|
||||
{ id: 'heart', label: 'Heart', icon: Heart },
|
||||
{ id: 'star', label: 'Star', icon: Star },
|
||||
{ id: 'music', label: 'Music', icon: Music },
|
||||
{ id: 'folder', label: 'Folder', icon: Folder },
|
||||
{ id: 'disc', label: 'Disc', icon: Disc },
|
||||
{ id: 'library', label: 'Library', icon: Library },
|
||||
];
|
||||
|
||||
const tabLabels: Record<string, string> = {
|
||||
tracks: 'Tracks',
|
||||
albums: 'Albums',
|
||||
artists: 'Artists',
|
||||
playlists: 'Playlists',
|
||||
};
|
||||
|
||||
function selectPreset(presetId: string) {
|
||||
customIconPreset = presetId;
|
||||
useCustomImage = false;
|
||||
customIconPath = null;
|
||||
}
|
||||
|
||||
async function handleUploadClick() {
|
||||
try {
|
||||
const selected = await open({
|
||||
multiple: false,
|
||||
filters: [{
|
||||
name: 'Images',
|
||||
extensions: ['png', 'jpg', 'jpeg', 'webp', 'gif']
|
||||
}]
|
||||
});
|
||||
|
||||
if (selected && typeof selected === 'string') {
|
||||
customIconPath = selected;
|
||||
useCustomImage = true;
|
||||
customIconPreset = null;
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Failed to open file picker:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function moveUp(index: number) {
|
||||
if (index === 0) return;
|
||||
const temp = tabOrder[index];
|
||||
tabOrder[index] = tabOrder[index - 1];
|
||||
tabOrder[index - 1] = temp;
|
||||
}
|
||||
|
||||
function moveDown(index: number) {
|
||||
if (index === tabOrder.length - 1) return;
|
||||
const temp = tabOrder[index];
|
||||
tabOrder[index] = tabOrder[index + 1];
|
||||
tabOrder[index + 1] = temp;
|
||||
}
|
||||
|
||||
async function handleSave() {
|
||||
saving = true;
|
||||
try {
|
||||
const prefs: FavoritesPreferences = {
|
||||
custom_icon_path: useCustomImage ? customIconPath : null,
|
||||
custom_icon_preset: useCustomImage ? null : customIconPreset,
|
||||
tab_order: tabOrder,
|
||||
};
|
||||
|
||||
await invoke('save_favorites_preferences', { prefs });
|
||||
onSave(prefs);
|
||||
onClose();
|
||||
} catch (err) {
|
||||
console.error('Failed to save favorites preferences:', err);
|
||||
} finally {
|
||||
saving = false;
|
||||
}
|
||||
}
|
||||
|
||||
function handleCancel() {
|
||||
customIconPath = initialPreferences.custom_icon_path || null;
|
||||
customIconPreset = initialPreferences.custom_icon_preset || 'heart';
|
||||
tabOrder = [...initialPreferences.tab_order];
|
||||
useCustomImage = !!initialPreferences.custom_icon_path;
|
||||
onClose();
|
||||
}
|
||||
</script>
|
||||
|
||||
<Modal {isOpen} onClose={handleCancel} title="Favorites Settings" maxWidth="720px">
|
||||
{#snippet children()}
|
||||
<div class="modal-section">
|
||||
<h3>Icon</h3>
|
||||
<p class="section-description">Choose an icon for the Favorites page header</p>
|
||||
|
||||
<div class="icon-grid">
|
||||
{#each presetIcons as preset}
|
||||
<button
|
||||
class="icon-preset-btn"
|
||||
class:active={!useCustomImage && customIconPreset === preset.id}
|
||||
onclick={() => selectPreset(preset.id)}
|
||||
title={preset.label}
|
||||
>
|
||||
<svelte:component this={preset.icon} size={24} />
|
||||
</button>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<div class="custom-upload">
|
||||
<button class="upload-btn" onclick={handleUploadClick}>
|
||||
<Upload size={16} />
|
||||
<span>Upload Custom Image</span>
|
||||
</button>
|
||||
{#if useCustomImage && customIconPath}
|
||||
<span class="upload-filename">{customIconPath.split('/').pop()}</span>
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-section">
|
||||
<h3>Tab Order</h3>
|
||||
<p class="section-description">Reorder tabs in the Favorites page navigation</p>
|
||||
|
||||
<div class="tab-order-list">
|
||||
{#each tabOrder as tab, index}
|
||||
<div class="tab-order-item">
|
||||
<div class="tab-grip">
|
||||
<GripVertical size={16} />
|
||||
</div>
|
||||
<div class="tab-label">{tabLabels[tab] || tab}</div>
|
||||
<div class="tab-controls">
|
||||
<button
|
||||
class="tab-move-btn"
|
||||
onclick={() => moveUp(index)}
|
||||
disabled={index === 0}
|
||||
title="Move up"
|
||||
>
|
||||
↑
|
||||
</button>
|
||||
<button
|
||||
class="tab-move-btn"
|
||||
onclick={() => moveDown(index)}
|
||||
disabled={index === tabOrder.length - 1}
|
||||
title="Move down"
|
||||
>
|
||||
↓
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
</div>
|
||||
{/snippet}
|
||||
|
||||
{#snippet footer()}
|
||||
<div class="modal-actions">
|
||||
<button class="btn btn-secondary" onclick={handleCancel} disabled={saving}>
|
||||
Cancel
|
||||
</button>
|
||||
<button class="btn btn-primary" onclick={handleSave} disabled={saving}>
|
||||
{saving ? 'Saving...' : 'Save'}
|
||||
</button>
|
||||
</div>
|
||||
{/snippet}
|
||||
</Modal>
|
||||
|
||||
<style>
|
||||
.modal-section {
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
|
||||
.modal-section:last-of-type {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.modal-section h3 {
|
||||
font-size: 15px;
|
||||
font-weight: 600;
|
||||
margin: 0 0 4px 0;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.section-description {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
margin: 0 0 16px 0;
|
||||
}
|
||||
|
||||
.icon-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(6, 1fr);
|
||||
gap: 12px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.icon-preset-btn {
|
||||
aspect-ratio: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--bg-secondary);
|
||||
border: 2px solid transparent;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.icon-preset-btn:hover {
|
||||
background: var(--bg-tertiary);
|
||||
border-color: var(--accent-primary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.icon-preset-btn.active {
|
||||
background: var(--accent-primary);
|
||||
border-color: var(--accent-primary);
|
||||
color: var(--bg-primary);
|
||||
}
|
||||
|
||||
.custom-upload {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.upload-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 6px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.upload-btn:hover {
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.upload-filename {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tab-order-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tab-order-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 12px 16px;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.tab-grip {
|
||||
color: var(--text-muted);
|
||||
cursor: grab;
|
||||
}
|
||||
|
||||
.tab-label {
|
||||
flex: 1;
|
||||
font-size: 14px;
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tab-controls {
|
||||
display: flex;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.tab-move-btn {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--bg-primary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 4px;
|
||||
color: var(--text-secondary);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.tab-move-btn:hover:not(:disabled) {
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.tab-move-btn:disabled {
|
||||
opacity: 0.3;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.modal-actions {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
gap: 12px;
|
||||
padding-top: 24px;
|
||||
border-top: 1px solid var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.btn {
|
||||
padding: 8px 20px;
|
||||
border-radius: 6px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
border: none;
|
||||
}
|
||||
|
||||
.btn-secondary {
|
||||
background: var(--bg-secondary);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.btn-secondary:hover:not(:disabled) {
|
||||
background: var(--bg-tertiary);
|
||||
}
|
||||
|
||||
.btn-primary {
|
||||
background: var(--accent-primary);
|
||||
color: var(--bg-primary);
|
||||
}
|
||||
|
||||
.btn-primary:hover:not(:disabled) {
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.btn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
@@ -1,12 +1,14 @@
|
||||
<script lang="ts">
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { onMount } from 'svelte';
|
||||
import { Heart, Play, Disc3, Mic2, Music, Search, X, LayoutGrid, List, ChevronDown, ListMusic } from 'lucide-svelte';
|
||||
import { Heart, Play, Disc3, Mic2, Music, Search, X, LayoutGrid, List, ChevronDown, ListMusic, Edit3 } from 'lucide-svelte';
|
||||
import AlbumCard from '../AlbumCard.svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import PlaylistCollage from '../PlaylistCollage.svelte';
|
||||
import FavoritesEditModal from '../FavoritesEditModal.svelte';
|
||||
import { type DownloadStatus } from '$lib/stores/downloadState';
|
||||
import { setPlaybackContext } from '$lib/stores/playbackContextStore';
|
||||
import type { FavoritesPreferences } from '$lib/types';
|
||||
|
||||
interface FavoriteAlbum {
|
||||
id: string;
|
||||
@@ -131,6 +133,12 @@
|
||||
|
||||
let loading = $state(false);
|
||||
let loadingPlaylists = $state(false);
|
||||
let editModalOpen = $state(false);
|
||||
let favoritesPreferences = $state<FavoritesPreferences>({
|
||||
custom_icon_path: null,
|
||||
custom_icon_preset: 'heart',
|
||||
tab_order: ['tracks', 'albums', 'artists', 'playlists'],
|
||||
});
|
||||
|
||||
// Download status tracking
|
||||
let albumDownloadStatuses = $state<Map<string, boolean>>(new Map());
|
||||
@@ -249,8 +257,23 @@
|
||||
trackGroupingEnabled = loadStoredBool('qbz-favorites-track-group-enabled', false);
|
||||
artistGroupingEnabled = loadStoredBool('qbz-favorites-artist-group-enabled', false);
|
||||
loadFavorites('tracks');
|
||||
loadFavoritesPreferences();
|
||||
});
|
||||
|
||||
async function loadFavoritesPreferences() {
|
||||
try {
|
||||
const prefs = await invoke<FavoritesPreferences>('get_favorites_preferences');
|
||||
favoritesPreferences = prefs;
|
||||
} catch (err) {
|
||||
console.error('Failed to load favorites preferences:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function handlePreferencesSaved(prefs: FavoritesPreferences) {
|
||||
favoritesPreferences = prefs;
|
||||
}
|
||||
|
||||
|
||||
$effect(() => {
|
||||
try {
|
||||
localStorage.setItem('qbz-favorites-album-view', albumViewMode);
|
||||
@@ -649,6 +672,9 @@
|
||||
<h1>Favorites</h1>
|
||||
<p class="subtitle">Your liked tracks, albums, and artists</p>
|
||||
</div>
|
||||
<button class="edit-btn" onclick={() => editModalOpen = true} title="Edit Favorites settings">
|
||||
<Edit3 size={16} />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Tabs -->
|
||||
@@ -1298,6 +1324,13 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<FavoritesEditModal
|
||||
isOpen={editModalOpen}
|
||||
onClose={() => editModalOpen = false}
|
||||
onSave={handlePreferencesSaved}
|
||||
initialPreferences={favoritesPreferences}
|
||||
/>
|
||||
|
||||
<style>
|
||||
.favorites-view {
|
||||
padding: 24px;
|
||||
@@ -1330,6 +1363,7 @@
|
||||
align-items: center;
|
||||
gap: 20px;
|
||||
margin-bottom: 32px;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.header-icon {
|
||||
@@ -1342,6 +1376,10 @@
|
||||
border-radius: 16px;
|
||||
}
|
||||
|
||||
.header-content {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.header-content h1 {
|
||||
font-size: 24px;
|
||||
font-weight: 700;
|
||||
@@ -1355,6 +1393,29 @@
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.edit-btn {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: var(--bg-secondary);
|
||||
border: 1px solid var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
color: var(--text-secondary);
|
||||
cursor: pointer;
|
||||
transition: all 150ms ease;
|
||||
}
|
||||
|
||||
.edit-btn:hover {
|
||||
background: var(--bg-tertiary);
|
||||
color: var(--text-primary);
|
||||
border-color: var(--accent-primary);
|
||||
}
|
||||
|
||||
.tabs {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
|
||||
@@ -196,7 +196,25 @@
|
||||
"artists": "Artists",
|
||||
"noFavorites": "No favorites yet",
|
||||
"addedToFavorites": "Added to favorites",
|
||||
"removedFromFavorites": "Removed from favorites"
|
||||
"removedFromFavorites": "Removed from favorites",
|
||||
"editSettings": "Edit Favorites Settings",
|
||||
"settingsModalTitle": "Favorites Settings",
|
||||
"iconSectionTitle": "Icon",
|
||||
"iconSectionDescription": "Choose an icon for the Favorites page header",
|
||||
"uploadCustomImage": "Upload Custom Image",
|
||||
"tabOrderSectionTitle": "Tab Order",
|
||||
"tabOrderSectionDescription": "Reorder tabs in the Favorites page navigation",
|
||||
"tabLabels": {
|
||||
"tracks": "Tracks",
|
||||
"albums": "Albums",
|
||||
"artists": "Artists",
|
||||
"playlists": "Playlists"
|
||||
},
|
||||
"moveUp": "Move up",
|
||||
"moveDown": "Move down",
|
||||
"save": "Save",
|
||||
"saving": "Saving...",
|
||||
"cancel": "Cancel"
|
||||
},
|
||||
"player": {
|
||||
"nowPlaying": "Now Playing",
|
||||
|
||||
@@ -196,7 +196,25 @@
|
||||
"artists": "Artistas",
|
||||
"noFavorites": "Aún no hay favoritos",
|
||||
"addedToFavorites": "Agregado a favoritos",
|
||||
"removedFromFavorites": "Eliminado de favoritos"
|
||||
"removedFromFavorites": "Eliminado de favoritos",
|
||||
"editSettings": "Editar configuracion de Favoritos",
|
||||
"settingsModalTitle": "Configuracion de Favoritos",
|
||||
"iconSectionTitle": "Icono",
|
||||
"iconSectionDescription": "Elige un icono para el encabezado de la pagina de Favoritos",
|
||||
"uploadCustomImage": "Subir imagen personalizada",
|
||||
"tabOrderSectionTitle": "Orden de pestanas",
|
||||
"tabOrderSectionDescription": "Reordena las pestanas en la navegacion de Favoritos",
|
||||
"tabLabels": {
|
||||
"tracks": "Pistas",
|
||||
"albums": "Albumes",
|
||||
"artists": "Artistas",
|
||||
"playlists": "Listas"
|
||||
},
|
||||
"moveUp": "Subir",
|
||||
"moveDown": "Bajar",
|
||||
"save": "Guardar",
|
||||
"saving": "Guardando...",
|
||||
"cancel": "Cancelar"
|
||||
},
|
||||
"player": {
|
||||
"nowPlaying": "Reproduciendo",
|
||||
|
||||
@@ -244,3 +244,11 @@ export interface SongLinkResponse {
|
||||
identifier: string;
|
||||
contentType: string;
|
||||
}
|
||||
|
||||
// ============ Preferences Types ============
|
||||
|
||||
export interface FavoritesPreferences {
|
||||
custom_icon_path: string | null;
|
||||
custom_icon_preset: string | null;
|
||||
tab_order: string[];
|
||||
}
|
||||
Reference in new issue
Block a user