feat: album/playlist header menu and UI consistency
Album/Playlist Menu: - Remove + and Download buttons from headers - Add AlbumMenu component with: Play Next, Play Later, Share (Qobuz/song.link), Download - Implement queue handlers (handleAddAlbumToQueueNext, handleAddAlbumToQueueLater) - Implement share handlers (shareAlbumQobuzLink, shareAlbumSonglink) - Apply same menu to PlaylistDetailView Button consistency (no more pills): - AlbumDetailView: border-radius 20px → 8px - PlaylistDetailView: border-radius 24px → 8px - ArtistDetailView: border-radius 20px → 8px - FavoritesView: border-radius 20px → 8px - LocalLibraryView: border-radius 24px/20px → 8px UserCard simplified (previous commit)
This commit is contained in:
1 parent
c4203a195d
commit
73ef1f91db
7 files changed
+430
-40
No files matched your search
@@ -0,0 +1,308 @@
|
||||
<script lang="ts">
|
||||
import { tick } from 'svelte';
|
||||
import {
|
||||
ChevronRight,
|
||||
MoreHorizontal,
|
||||
ListPlus,
|
||||
ListEnd,
|
||||
Share2,
|
||||
Download,
|
||||
Link
|
||||
} from 'lucide-svelte';
|
||||
|
||||
interface Props {
|
||||
onPlayNext?: () => void;
|
||||
onPlayLater?: () => void;
|
||||
onShareQobuz?: () => void;
|
||||
onShareSonglink?: () => void;
|
||||
onDownload?: () => void;
|
||||
}
|
||||
|
||||
let {
|
||||
onPlayNext,
|
||||
onPlayLater,
|
||||
onShareQobuz,
|
||||
onShareSonglink,
|
||||
onDownload
|
||||
}: Props = $props();
|
||||
|
||||
let isOpen = $state(false);
|
||||
let shareOpen = $state(false);
|
||||
let menuRef: HTMLDivElement | null = null;
|
||||
let triggerRef: HTMLButtonElement | null = null;
|
||||
let menuEl: HTMLDivElement | null = null;
|
||||
let shareTriggerRef: HTMLDivElement | null = null;
|
||||
let submenuEl: HTMLDivElement | null = null;
|
||||
let menuStyle = $state('');
|
||||
let submenuStyle = $state('');
|
||||
|
||||
const hasQueue = $derived(!!(onPlayNext || onPlayLater));
|
||||
const hasShare = $derived(!!(onShareQobuz || onShareSonglink));
|
||||
const hasDownload = $derived(!!onDownload);
|
||||
const hasMenu = $derived(hasQueue || hasShare || hasDownload);
|
||||
|
||||
function closeMenu() {
|
||||
isOpen = false;
|
||||
shareOpen = false;
|
||||
}
|
||||
|
||||
function handleClickOutside(event: MouseEvent) {
|
||||
if (menuRef && !menuRef.contains(event.target as Node)) {
|
||||
closeMenu();
|
||||
}
|
||||
}
|
||||
|
||||
async function setMenuPosition() {
|
||||
await tick();
|
||||
if (!triggerRef || !menuEl) return;
|
||||
|
||||
const triggerRect = triggerRef.getBoundingClientRect();
|
||||
const menuRect = menuEl.getBoundingClientRect();
|
||||
const padding = 8;
|
||||
|
||||
let left = triggerRect.right - menuRect.width;
|
||||
let top = triggerRect.bottom + 6;
|
||||
|
||||
if (left < padding) left = padding;
|
||||
if (left + menuRect.width > window.innerWidth - padding) {
|
||||
left = Math.max(padding, window.innerWidth - menuRect.width - padding);
|
||||
}
|
||||
|
||||
if (top + menuRect.height > window.innerHeight - padding) {
|
||||
top = triggerRect.top - menuRect.height - 6;
|
||||
if (top < padding) top = padding;
|
||||
}
|
||||
|
||||
menuStyle = `left: ${left}px; top: ${top}px;`;
|
||||
}
|
||||
|
||||
async function setSubmenuPosition() {
|
||||
await tick();
|
||||
if (!shareTriggerRef || !submenuEl) return;
|
||||
|
||||
const triggerRect = shareTriggerRef.getBoundingClientRect();
|
||||
const submenuRect = submenuEl.getBoundingClientRect();
|
||||
const padding = 8;
|
||||
|
||||
const spaceRight = window.innerWidth - triggerRect.right;
|
||||
const openRight = spaceRight >= submenuRect.width + padding;
|
||||
|
||||
let left = openRight
|
||||
? triggerRect.right + 6
|
||||
: triggerRect.left - submenuRect.width - 6;
|
||||
let top = triggerRect.top - 6;
|
||||
|
||||
if (left < padding) left = padding;
|
||||
if (left + submenuRect.width > window.innerWidth - padding) {
|
||||
left = Math.max(padding, window.innerWidth - submenuRect.width - padding);
|
||||
}
|
||||
|
||||
if (top + submenuRect.height > window.innerHeight - padding) {
|
||||
top = window.innerHeight - submenuRect.height - padding;
|
||||
}
|
||||
if (top < padding) top = padding;
|
||||
|
||||
submenuStyle = `left: ${left}px; top: ${top}px;`;
|
||||
}
|
||||
|
||||
function handleAction(action?: () => void) {
|
||||
if (!action) return;
|
||||
action();
|
||||
closeMenu();
|
||||
}
|
||||
|
||||
$effect(() => {
|
||||
if (isOpen) {
|
||||
document.addEventListener('mousedown', handleClickOutside);
|
||||
const handleResize = () => setMenuPosition();
|
||||
const handleScroll = () => {
|
||||
setMenuPosition();
|
||||
if (shareOpen) setSubmenuPosition();
|
||||
};
|
||||
|
||||
window.addEventListener('resize', handleResize);
|
||||
window.addEventListener('scroll', handleScroll, true);
|
||||
return () => {
|
||||
document.removeEventListener('mousedown', handleClickOutside);
|
||||
window.removeEventListener('resize', handleResize);
|
||||
window.removeEventListener('scroll', handleScroll, true);
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
{#if hasMenu}
|
||||
<div
|
||||
class="album-menu"
|
||||
bind:this={menuRef}
|
||||
onmousedown={(e) => e.stopPropagation()}
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<button
|
||||
class="menu-trigger icon-btn"
|
||||
bind:this={triggerRef}
|
||||
onclick={(e) => {
|
||||
e.stopPropagation();
|
||||
isOpen = !isOpen;
|
||||
shareOpen = false;
|
||||
if (isOpen) setMenuPosition();
|
||||
}}
|
||||
aria-label="Album actions"
|
||||
>
|
||||
<MoreHorizontal size={20} color="white" />
|
||||
</button>
|
||||
|
||||
{#if isOpen}
|
||||
<div class="menu" bind:this={menuEl} style={menuStyle}>
|
||||
{#if hasQueue}
|
||||
{#if onPlayNext}
|
||||
<button class="menu-item" onclick={() => handleAction(onPlayNext)}>
|
||||
<ListPlus size={14} />
|
||||
<span>Play next</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if onPlayLater}
|
||||
<button class="menu-item" onclick={() => handleAction(onPlayLater)}>
|
||||
<ListEnd size={14} />
|
||||
<span>Play later</span>
|
||||
</button>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if hasQueue && (hasShare || hasDownload)}
|
||||
<div class="separator"></div>
|
||||
{/if}
|
||||
|
||||
{#if hasShare}
|
||||
<div
|
||||
class="menu-item submenu-trigger"
|
||||
bind:this={shareTriggerRef}
|
||||
onmouseenter={() => {
|
||||
shareOpen = true;
|
||||
setSubmenuPosition();
|
||||
}}
|
||||
onclick={() => {
|
||||
shareOpen = !shareOpen;
|
||||
if (shareOpen) setSubmenuPosition();
|
||||
}}
|
||||
>
|
||||
<Share2 size={14} />
|
||||
<span>Share</span>
|
||||
<ChevronRight size={14} class="chevron" />
|
||||
{#if shareOpen}
|
||||
<div class="submenu" bind:this={submenuEl} style={submenuStyle}>
|
||||
{#if onShareQobuz}
|
||||
<button class="menu-item" onclick={() => handleAction(onShareQobuz)}>
|
||||
<Link size={14} />
|
||||
<span>Qobuz link</span>
|
||||
</button>
|
||||
{/if}
|
||||
{#if onShareSonglink}
|
||||
<button class="menu-item" onclick={() => handleAction(onShareSonglink)}>
|
||||
<Link size={14} />
|
||||
<span>Song.link</span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if hasShare && hasDownload}
|
||||
<div class="separator"></div>
|
||||
{/if}
|
||||
|
||||
{#if hasDownload}
|
||||
<button class="menu-item" onclick={() => handleAction(onDownload)}>
|
||||
<Download size={14} />
|
||||
<span>Download album</span>
|
||||
</button>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.album-menu {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.menu-trigger {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: none;
|
||||
border: none;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
border-radius: 50%;
|
||||
transition: background-color 150ms ease;
|
||||
}
|
||||
|
||||
.menu-trigger:hover {
|
||||
background-color: rgba(255, 255, 255, 0.1);
|
||||
}
|
||||
|
||||
.menu {
|
||||
position: fixed;
|
||||
min-width: 180px;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
padding: 4px 0;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
|
||||
z-index: 60;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
width: 100%;
|
||||
padding: 10px 14px;
|
||||
background: none;
|
||||
border: none;
|
||||
color: var(--text-secondary);
|
||||
text-align: left;
|
||||
font-size: 13px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
transition: background-color 150ms ease, color 150ms ease;
|
||||
}
|
||||
|
||||
.menu-item span {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.menu-item :global(.chevron) {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.menu-item:hover {
|
||||
background-color: var(--bg-hover);
|
||||
color: var(--text-primary);
|
||||
}
|
||||
|
||||
.separator {
|
||||
height: 1px;
|
||||
background-color: var(--bg-hover);
|
||||
margin: 4px 0;
|
||||
}
|
||||
|
||||
.submenu-trigger {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.submenu {
|
||||
position: fixed;
|
||||
min-width: 160px;
|
||||
background-color: var(--bg-tertiary);
|
||||
border-radius: 8px;
|
||||
padding: 4px 0;
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
|
||||
z-index: 70;
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { onMount } from 'svelte';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { ArrowLeft, Play, Shuffle, Heart, Plus, MoreHorizontal, Download } from 'lucide-svelte';
|
||||
import { ArrowLeft, Play, Shuffle, Heart } from 'lucide-svelte';
|
||||
import TrackRow from '../TrackRow.svelte';
|
||||
import AlbumMenu from '../AlbumMenu.svelte';
|
||||
import { getDownloadState, type DownloadStatus } from '$lib/stores/downloadState';
|
||||
|
||||
interface Track {
|
||||
@@ -46,12 +47,15 @@
|
||||
onTrackGoToArtist?: (artistId: number) => void;
|
||||
onPlayAll?: () => void;
|
||||
onShuffleAll?: () => void;
|
||||
onAddToQueue?: () => void;
|
||||
onPlayAllNext?: () => void;
|
||||
onPlayAllLater?: () => void;
|
||||
onAddTrackToPlaylist?: (trackId: number) => void;
|
||||
onTrackDownload?: (track: Track) => void;
|
||||
onTrackRemoveDownload?: (trackId: number) => void;
|
||||
getTrackDownloadStatus?: (trackId: number) => { status: DownloadStatus; progress: number };
|
||||
onDownloadAlbum?: () => void;
|
||||
onShareAlbumQobuz?: () => void;
|
||||
onShareAlbumSonglink?: () => void;
|
||||
downloadStateVersion?: number;
|
||||
}
|
||||
|
||||
@@ -69,12 +73,15 @@
|
||||
onTrackGoToArtist,
|
||||
onPlayAll,
|
||||
onShuffleAll,
|
||||
onAddToQueue,
|
||||
onPlayAllNext,
|
||||
onPlayAllLater,
|
||||
onAddTrackToPlaylist,
|
||||
onTrackDownload,
|
||||
onTrackRemoveDownload,
|
||||
getTrackDownloadStatus,
|
||||
onDownloadAlbum,
|
||||
onShareAlbumQobuz,
|
||||
onShareAlbumSonglink,
|
||||
downloadStateVersion
|
||||
}: Props = $props();
|
||||
|
||||
@@ -187,17 +194,13 @@
|
||||
fill={isFavorite ? 'var(--accent-primary)' : 'none'}
|
||||
/>
|
||||
</button>
|
||||
<button class="icon-btn" onclick={onAddToQueue}>
|
||||
<Plus size={20} color="white" />
|
||||
</button>
|
||||
{#if onDownloadAlbum}
|
||||
<button class="icon-btn" onclick={onDownloadAlbum} title="Download album">
|
||||
<Download size={20} color="white" />
|
||||
</button>
|
||||
{/if}
|
||||
<button class="icon-btn">
|
||||
<MoreHorizontal size={20} color="white" />
|
||||
</button>
|
||||
<AlbumMenu
|
||||
onPlayNext={onPlayAllNext}
|
||||
onPlayLater={onPlayAllLater}
|
||||
onShareQobuz={onShareAlbumQobuz}
|
||||
onShareSonglink={onShareAlbumSonglink}
|
||||
onDownload={onDownloadAlbum}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -517,7 +517,7 @@
|
||||
padding: 8px 16px;
|
||||
background-color: var(--accent-primary);
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
border-radius: 8px;
|
||||
color: white;
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
|
||||
@@ -518,7 +518,7 @@
|
||||
padding: 10px 20px;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
border-radius: 8px;
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
@@ -606,7 +606,7 @@
|
||||
background-color: var(--accent-primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
@@ -625,7 +625,7 @@
|
||||
background: none;
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--text-muted);
|
||||
border-radius: 20px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
|
||||
@@ -998,7 +998,7 @@
|
||||
padding: 10px 20px;
|
||||
background: none;
|
||||
border: none;
|
||||
border-radius: 20px;
|
||||
border-radius: 8px;
|
||||
color: var(--text-muted);
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
@@ -1248,7 +1248,7 @@
|
||||
background: var(--accent-primary);
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 24px;
|
||||
border-radius: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<script lang="ts">
|
||||
import { ArrowLeft, Play, Shuffle, Plus, ListMusic, Search, X, ChevronDown, ImagePlus, HardDrive, Info } from 'lucide-svelte';
|
||||
import { ArrowLeft, Play, Shuffle, ListMusic, Search, X, ChevronDown, ImagePlus, HardDrive, Info } from 'lucide-svelte';
|
||||
import AlbumMenu from '../AlbumMenu.svelte';
|
||||
import { writeText } from '@tauri-apps/plugin-clipboard-manager';
|
||||
import { invoke } from '@tauri-apps/api/core';
|
||||
import { open } from '@tauri-apps/plugin-dialog';
|
||||
import { onMount } from 'svelte';
|
||||
@@ -430,24 +432,58 @@
|
||||
}
|
||||
}
|
||||
|
||||
async function handleAddToQueue() {
|
||||
if (tracks.length > 0) {
|
||||
const queueTracks = tracks.map(t => ({
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
artist: t.artist || 'Unknown Artist',
|
||||
album: t.album || playlist?.name || 'Playlist',
|
||||
duration_secs: t.durationSeconds,
|
||||
artwork_url: t.albumArt || getPlaylistImage(),
|
||||
}));
|
||||
|
||||
async function handlePlayAllNext() {
|
||||
if (tracks.length === 0) return;
|
||||
// Add in reverse order so first track ends up right after current
|
||||
for (let i = tracks.length - 1; i >= 0; i--) {
|
||||
const t = tracks[i];
|
||||
try {
|
||||
await invoke('add_tracks_to_queue', { tracks: queueTracks });
|
||||
await invoke('add_track_next', {
|
||||
track: {
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
artist: t.artist || 'Unknown Artist',
|
||||
album: t.album || playlist?.name || 'Playlist',
|
||||
duration_secs: t.durationSeconds,
|
||||
artwork_url: t.albumArt || getPlaylistImage(),
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Failed to add to queue:', err);
|
||||
console.error('Failed to add track next:', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function handlePlayAllLater() {
|
||||
if (tracks.length === 0) return;
|
||||
const queueTracks = tracks.map(t => ({
|
||||
id: t.id,
|
||||
title: t.title,
|
||||
artist: t.artist || 'Unknown Artist',
|
||||
album: t.album || playlist?.name || 'Playlist',
|
||||
duration_secs: t.durationSeconds,
|
||||
artwork_url: t.albumArt || getPlaylistImage(),
|
||||
}));
|
||||
|
||||
try {
|
||||
await invoke('add_tracks_to_queue', { tracks: queueTracks });
|
||||
} catch (err) {
|
||||
console.error('Failed to add to queue:', err);
|
||||
}
|
||||
}
|
||||
|
||||
function sharePlaylistQobuz() {
|
||||
if (!playlist?.id) return;
|
||||
const url = `https://play.qobuz.com/playlist/${playlist.id}`;
|
||||
writeText(url);
|
||||
}
|
||||
|
||||
function sharePlaylistSonglink() {
|
||||
if (!playlist?.id) return;
|
||||
const qobuzUrl = `https://play.qobuz.com/playlist/${playlist.id}`;
|
||||
const songlinkUrl = `https://song.link/${encodeURIComponent(qobuzUrl)}`;
|
||||
writeText(songlinkUrl);
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="playlist-detail">
|
||||
@@ -525,9 +561,12 @@
|
||||
<Shuffle size={18} />
|
||||
<span>Shuffle</span>
|
||||
</button>
|
||||
<button class="icon-btn" onclick={handleAddToQueue} title="Add all to queue">
|
||||
<Plus size={20} color="white" />
|
||||
</button>
|
||||
<AlbumMenu
|
||||
onPlayNext={handlePlayAllNext}
|
||||
onPlayLater={handlePlayAllLater}
|
||||
onShareQobuz={sharePlaylistQobuz}
|
||||
onShareSonglink={sharePlaylistSonglink}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user