The first public release of Fabled Minstrel #158
@@ -1,145 +1,32 @@
|
||||
<script lang="ts">
|
||||
import { MoreVertical, Heart, HeartOff, ListMusic, Plus, Disc3 } from 'lucide-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
||||
import { listAlbumTracks } from '#lib/api/albums.js';
|
||||
import { enqueueTracks } from '#lib/player/store.svelte.js';
|
||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
||||
import CollectionMenu from './CollectionMenu.svelte';
|
||||
import type { TrackRef } from '#lib/api/types.js';
|
||||
|
||||
// An album's ⋮ menu: like, queue, add to playlist, go to artist.
|
||||
let {
|
||||
albumId,
|
||||
albumTitle,
|
||||
artistId,
|
||||
artistName,
|
||||
tracks,
|
||||
direction = 'down'
|
||||
}: {
|
||||
albumId: string;
|
||||
albumTitle: string;
|
||||
artistId: string;
|
||||
artistName: string;
|
||||
artistName?: string;
|
||||
/** Pre-loaded tracks; fetched on first use when omitted. */
|
||||
tracks?: TrackRef[];
|
||||
direction?: 'up' | 'down';
|
||||
} = $props();
|
||||
|
||||
let menuOpen = $state(false);
|
||||
let addOpen = $state(false);
|
||||
// Lazy track cache. Starts null so the `tracks` prop is read inside
|
||||
// ensureTracks() each call rather than captured at component-creation
|
||||
// time — the menu is reused across different album rows, and pinning
|
||||
// the prop's initial value here would serve a stale list when the
|
||||
// user opens the menu on a second album.
|
||||
let cachedTracks: TrackRef[] | null = $state(null);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const likedQ = $derived(createLikedIdsQuery());
|
||||
const liked = $derived.by(() => {
|
||||
const data = $likedQ?.data;
|
||||
if (!data) return false;
|
||||
return data.album_ids.includes(albumId);
|
||||
});
|
||||
|
||||
function toggleMenu(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
menuOpen = !menuOpen;
|
||||
}
|
||||
|
||||
function closeAll() {
|
||||
menuOpen = false;
|
||||
addOpen = false;
|
||||
}
|
||||
|
||||
async function ensureTracks(): Promise<TrackRef[]> {
|
||||
if (cachedTracks) return cachedTracks;
|
||||
if (tracks) {
|
||||
cachedTracks = tracks;
|
||||
return tracks;
|
||||
}
|
||||
const fetched = await listAlbumTracks(albumId);
|
||||
cachedTracks = fetched;
|
||||
return fetched;
|
||||
}
|
||||
|
||||
async function onAddToQueue() {
|
||||
const ts = await ensureTracks();
|
||||
enqueueTracks(ts);
|
||||
closeAll();
|
||||
}
|
||||
|
||||
async function onOpenAddToPlaylist() {
|
||||
await ensureTracks();
|
||||
menuOpen = false;
|
||||
addOpen = true;
|
||||
}
|
||||
|
||||
async function onToggleLike() {
|
||||
closeAll();
|
||||
if (liked) {
|
||||
await unlikeEntity(queryClient, 'album', albumId);
|
||||
} else {
|
||||
await likeEntity(queryClient, 'album', albumId);
|
||||
}
|
||||
}
|
||||
|
||||
function onGoToArtist() {
|
||||
closeAll();
|
||||
goto(`/artists/${artistId}`);
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (!menuOpen && !addOpen) return;
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
closeAll();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onclick={() => { menuOpen = false; addOpen = false; }} onkeydown={onKeydown} />
|
||||
|
||||
<div class="relative inline-block">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Album actions for ${albumTitle}`}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={menuOpen}
|
||||
onclick={toggleMenu}
|
||||
class="rounded p-1 text-text-muted hover:text-text-primary"
|
||||
>
|
||||
<MoreVertical size={16} strokeWidth={1} />
|
||||
</button>
|
||||
|
||||
{#if menuOpen}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- onclick is a click-outside guard (stops bubble to the
|
||||
<svelte:window onclick> menu-closer above); not user-facing
|
||||
interaction, so a paired keyboard handler is intentionally
|
||||
absent. Escape-to-close lives on svelte:window onkeydown. -->
|
||||
<div
|
||||
role="menu"
|
||||
tabindex="-1"
|
||||
class="absolute right-0 z-20 w-56 rounded-md border border-border bg-surface p-1 shadow-lg
|
||||
{direction === 'up' ? 'bottom-full mb-1' : 'top-full mt-1'}"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<TrackMenuItem
|
||||
icon={liked ? HeartOff : Heart}
|
||||
label={liked ? 'Unlike album' : 'Like album'}
|
||||
onclick={onToggleLike}
|
||||
/>
|
||||
<TrackMenuDivider />
|
||||
<TrackMenuItem icon={Plus} label="Add to queue" onclick={onAddToQueue} />
|
||||
<TrackMenuItem icon={ListMusic} label="Add to playlist…" onclick={onOpenAddToPlaylist} />
|
||||
<TrackMenuDivider />
|
||||
<TrackMenuItem icon={Disc3} label="Go to artist" onclick={onGoToArtist} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if addOpen && cachedTracks}
|
||||
<AddToPlaylistMenu tracks={cachedTracks} onClose={closeAll} />
|
||||
{/if}
|
||||
</div>
|
||||
<CollectionMenu
|
||||
entity="album"
|
||||
id={albumId}
|
||||
name={albumTitle}
|
||||
loadTracks={() => listAlbumTracks(albumId)}
|
||||
{tracks}
|
||||
{artistId}
|
||||
{direction}
|
||||
/>
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
<script lang="ts">
|
||||
import { MoreVertical, Heart, HeartOff, ListMusic, Plus } from 'lucide-svelte';
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
||||
import { listArtistTracks } from '#lib/api/artists.js';
|
||||
import { enqueueTracks } from '#lib/player/store.svelte.js';
|
||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
||||
import CollectionMenu from './CollectionMenu.svelte';
|
||||
import type { TrackRef } from '#lib/api/types.js';
|
||||
|
||||
// An artist's ⋮ menu: like, and queue or add to a playlist all their tracks.
|
||||
let {
|
||||
artistId,
|
||||
artistName,
|
||||
@@ -17,116 +12,17 @@
|
||||
}: {
|
||||
artistId: string;
|
||||
artistName: string;
|
||||
/** Pre-loaded tracks; menu fetches lazily on action click when omitted. */
|
||||
/** Pre-loaded tracks; fetched on first use when omitted. */
|
||||
tracks?: TrackRef[];
|
||||
/** Open above the trigger when used near the bottom of the viewport. */
|
||||
direction?: 'up' | 'down';
|
||||
} = $props();
|
||||
|
||||
let menuOpen = $state(false);
|
||||
let addOpen = $state(false);
|
||||
// Lazy track cache — see AlbumMenu.svelte for the same reasoning.
|
||||
// Starts null so the `tracks` prop is read inside ensureTracks() each
|
||||
// call rather than captured at component-creation time.
|
||||
let cachedTracks: TrackRef[] | null = $state(null);
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const likedQ = $derived(createLikedIdsQuery());
|
||||
const liked = $derived.by(() => {
|
||||
const data = $likedQ?.data;
|
||||
if (!data) return false;
|
||||
return data.artist_ids.includes(artistId);
|
||||
});
|
||||
|
||||
function toggleMenu(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
menuOpen = !menuOpen;
|
||||
}
|
||||
|
||||
function closeAll() {
|
||||
menuOpen = false;
|
||||
addOpen = false;
|
||||
}
|
||||
|
||||
async function ensureTracks(): Promise<TrackRef[]> {
|
||||
if (cachedTracks) return cachedTracks;
|
||||
if (tracks) {
|
||||
cachedTracks = tracks;
|
||||
return tracks;
|
||||
}
|
||||
const fetched = await listArtistTracks(artistId);
|
||||
cachedTracks = fetched;
|
||||
return fetched;
|
||||
}
|
||||
|
||||
async function onAddAllToQueue() {
|
||||
const ts = await ensureTracks();
|
||||
enqueueTracks(ts);
|
||||
closeAll();
|
||||
}
|
||||
|
||||
async function onOpenAddToPlaylist() {
|
||||
await ensureTracks();
|
||||
menuOpen = false;
|
||||
addOpen = true;
|
||||
}
|
||||
|
||||
async function onToggleLike() {
|
||||
closeAll();
|
||||
if (liked) {
|
||||
await unlikeEntity(queryClient, 'artist', artistId);
|
||||
} else {
|
||||
await likeEntity(queryClient, 'artist', artistId);
|
||||
}
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (!menuOpen && !addOpen) return;
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
closeAll();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onclick={() => { menuOpen = false; addOpen = false; }} onkeydown={onKeydown} />
|
||||
|
||||
<div class="relative inline-block">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Artist actions for ${artistName}`}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={menuOpen}
|
||||
onclick={toggleMenu}
|
||||
class="rounded p-1 text-text-muted hover:text-text-primary"
|
||||
>
|
||||
<MoreVertical size={16} strokeWidth={1} />
|
||||
</button>
|
||||
|
||||
{#if menuOpen}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- See AlbumMenu.svelte for the same intentional pattern: the
|
||||
onclick is a stopPropagation guard against the window-level
|
||||
menu-closer; Escape-to-close is on svelte:window onkeydown. -->
|
||||
<div
|
||||
role="menu"
|
||||
tabindex="-1"
|
||||
class="absolute right-0 z-20 w-56 rounded-md border border-border bg-surface p-1 shadow-lg
|
||||
{direction === 'up' ? 'bottom-full mb-1' : 'top-full mt-1'}"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
<TrackMenuItem
|
||||
icon={liked ? HeartOff : Heart}
|
||||
label={liked ? 'Unlike artist' : 'Like artist'}
|
||||
onclick={onToggleLike}
|
||||
/>
|
||||
<TrackMenuDivider />
|
||||
<TrackMenuItem icon={Plus} label="Add all to queue" onclick={onAddAllToQueue} />
|
||||
<TrackMenuItem icon={ListMusic} label="Add all to playlist…" onclick={onOpenAddToPlaylist} />
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{#if addOpen && cachedTracks}
|
||||
<AddToPlaylistMenu tracks={cachedTracks} onClose={closeAll} />
|
||||
{/if}
|
||||
</div>
|
||||
<CollectionMenu
|
||||
entity="artist"
|
||||
id={artistId}
|
||||
name={artistName}
|
||||
loadTracks={() => listArtistTracks(artistId)}
|
||||
{tracks}
|
||||
{direction}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
<script lang="ts">
|
||||
import { Heart, HeartOff, ListMusic, Plus, Disc3 } from 'lucide-svelte';
|
||||
import { goto } from '$app/navigation';
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
||||
import { enqueueTracks } from '#lib/player/store.svelte.js';
|
||||
import KebabMenu from './KebabMenu.svelte';
|
||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
||||
import type { TrackRef } from '#lib/api/types.js';
|
||||
|
||||
// The ⋮ menu for a whole album or artist: like it, queue its tracks, add
|
||||
// them to a playlist, and (for an album) go to its artist. AlbumMenu and
|
||||
// ArtistMenu are this with their entity filled in.
|
||||
let {
|
||||
entity,
|
||||
id,
|
||||
name,
|
||||
loadTracks,
|
||||
tracks,
|
||||
artistId,
|
||||
direction = 'down'
|
||||
}: {
|
||||
entity: 'album' | 'artist';
|
||||
id: string;
|
||||
name: string;
|
||||
/** Fetches the tracks when no `tracks` were given; called on first use. */
|
||||
loadTracks: () => Promise<TrackRef[]>;
|
||||
tracks?: TrackRef[];
|
||||
/** Adds "Go to artist". */
|
||||
artistId?: string;
|
||||
direction?: 'up' | 'down';
|
||||
} = $props();
|
||||
|
||||
let menuOpen = $state(false);
|
||||
let addOpen = $state(false);
|
||||
// The tracks, fetched on first use and kept per entity id: a menu reused
|
||||
// for another row (a virtualized list) refetches rather than serving the
|
||||
// first row's list.
|
||||
let cache: { id: string; tracks: TrackRef[] } | null = $state(null);
|
||||
|
||||
const noun = $derived(entity === 'album' ? 'album' : 'artist');
|
||||
// An artist's tracks span albums, so its actions say "all".
|
||||
const all = $derived(entity === 'artist' ? ' all' : '');
|
||||
|
||||
const queryClient = useQueryClient();
|
||||
const likedQ = $derived(createLikedIdsQuery());
|
||||
const liked = $derived.by(() => {
|
||||
const data = $likedQ?.data;
|
||||
if (!data) return false;
|
||||
return (entity === 'album' ? data.album_ids : data.artist_ids).includes(id);
|
||||
});
|
||||
|
||||
function closeAll() {
|
||||
menuOpen = false;
|
||||
addOpen = false;
|
||||
}
|
||||
|
||||
async function ensureTracks(): Promise<TrackRef[]> {
|
||||
if (cache?.id === id) return cache.tracks;
|
||||
const ts = tracks ?? (await loadTracks());
|
||||
cache = { id, tracks: ts };
|
||||
return ts;
|
||||
}
|
||||
|
||||
async function onAddToQueue() {
|
||||
enqueueTracks(await ensureTracks());
|
||||
closeAll();
|
||||
}
|
||||
|
||||
async function onOpenAddToPlaylist() {
|
||||
await ensureTracks();
|
||||
menuOpen = false;
|
||||
addOpen = true;
|
||||
}
|
||||
|
||||
async function onToggleLike() {
|
||||
closeAll();
|
||||
if (liked) await unlikeEntity(queryClient, entity, id);
|
||||
else await likeEntity(queryClient, entity, id);
|
||||
}
|
||||
|
||||
function onGoToArtist() {
|
||||
closeAll();
|
||||
goto(`/artists/${artistId}`);
|
||||
}
|
||||
</script>
|
||||
|
||||
<KebabMenu
|
||||
label={`${entity === 'album' ? 'Album' : 'Artist'} actions for ${name}`}
|
||||
bind:open={menuOpen}
|
||||
{direction}
|
||||
popoverOpen={addOpen}
|
||||
onclose={() => (addOpen = false)}
|
||||
>
|
||||
<TrackMenuItem
|
||||
icon={liked ? HeartOff : Heart}
|
||||
label={liked ? `Unlike ${noun}` : `Like ${noun}`}
|
||||
onclick={onToggleLike}
|
||||
/>
|
||||
<TrackMenuDivider />
|
||||
<TrackMenuItem icon={Plus} label={`Add${all} to queue`} onclick={onAddToQueue} />
|
||||
<TrackMenuItem icon={ListMusic} label={`Add${all} to playlist…`} onclick={onOpenAddToPlaylist} />
|
||||
{#if artistId}
|
||||
<TrackMenuDivider />
|
||||
<TrackMenuItem icon={Disc3} label="Go to artist" onclick={onGoToArtist} />
|
||||
{/if}
|
||||
|
||||
{#snippet after()}
|
||||
{#if addOpen && cache}
|
||||
<AddToPlaylistMenu tracks={cache.tracks} onClose={closeAll} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</KebabMenu>
|
||||
@@ -0,0 +1,92 @@
|
||||
<script lang="ts">
|
||||
import type { Snippet } from 'svelte';
|
||||
import { MoreVertical } from 'lucide-svelte';
|
||||
|
||||
// The ⋮ trigger and its popover, shared by every overflow menu. A click
|
||||
// anywhere else or Escape closes it. Popovers a menu opens from its items
|
||||
// (Add to playlist, Report a problem) render in `after`, beside the menu,
|
||||
// and close through onclose.
|
||||
let {
|
||||
label,
|
||||
open = $bindable(false),
|
||||
direction = 'down',
|
||||
width = 'w-56',
|
||||
triggerClass = 'rounded p-1 text-text-muted hover:text-text-primary',
|
||||
iconSize = 16,
|
||||
class: klass = '',
|
||||
popoverOpen = false,
|
||||
onclose,
|
||||
children,
|
||||
after
|
||||
}: {
|
||||
/** The trigger's accessible name, e.g. "Album actions for Blue". */
|
||||
label: string;
|
||||
open?: boolean;
|
||||
/** 'up' opens above the trigger, for use near the bottom of the screen. */
|
||||
direction?: 'up' | 'down';
|
||||
width?: string;
|
||||
triggerClass?: string;
|
||||
iconSize?: number;
|
||||
class?: string;
|
||||
/** Whether a popover in `after` is open, so Escape and an outside click
|
||||
reach it too. */
|
||||
popoverOpen?: boolean;
|
||||
/** Called when the menu closes on an outside click or Escape; close the
|
||||
`after` popovers here. Escape closes every one of them; an outside
|
||||
click leaves alone any that keep their own clicks. */
|
||||
onclose?: (why: 'outside' | 'escape') => void;
|
||||
children: Snippet;
|
||||
after?: Snippet;
|
||||
} = $props();
|
||||
|
||||
function closeOn(why: 'outside' | 'escape') {
|
||||
open = false;
|
||||
onclose?.(why);
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (e.key !== 'Escape' || (!open && !popoverOpen)) return;
|
||||
e.preventDefault();
|
||||
closeOn('escape');
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window
|
||||
onclick={() => (open || popoverOpen) && closeOn('outside')}
|
||||
onkeydown={onKeydown}
|
||||
/>
|
||||
|
||||
<div class="relative inline-block {klass}">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={label}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={open}
|
||||
onclick={(e) => {
|
||||
// A menu can sit inside a card's link; its trigger never follows it.
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
open = !open;
|
||||
}}
|
||||
class={triggerClass}
|
||||
>
|
||||
<MoreVertical size={iconSize} strokeWidth={1} />
|
||||
</button>
|
||||
|
||||
{#if open}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- The onclick keeps a click inside the menu from reaching the window
|
||||
handler that closes it; Escape is handled on the window. -->
|
||||
<div
|
||||
role="menu"
|
||||
tabindex="-1"
|
||||
class="absolute right-0 z-20 {width} rounded-md border border-border bg-surface p-1 shadow-lg
|
||||
{direction === 'up' ? 'bottom-full mb-1' : 'top-full mt-1'}"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{@render children()}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
{@render after?.()}
|
||||
</div>
|
||||
@@ -1,6 +1,6 @@
|
||||
<script lang="ts">
|
||||
import { plural } from '#lib/utils/plural.js';
|
||||
import { Play, MoreVertical, RefreshCcw } from 'lucide-svelte';
|
||||
import { Play, RefreshCcw } from 'lucide-svelte';
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
import type { Playlist, PlaylistTrack, TrackRef } from '#lib/api/types.js';
|
||||
import { user } from '#lib/auth/store.svelte.js';
|
||||
@@ -10,6 +10,7 @@
|
||||
import { refreshedLabel, songsLikeArtist, washTone } from '#lib/playlists/shelf.js';
|
||||
import { coverUrl } from '#lib/media/covers.js';
|
||||
import Cover from './Cover.svelte';
|
||||
import KebabMenu from './KebabMenu.svelte';
|
||||
import { dominantColorFromUrl, rgbToCssString } from '#lib/media/dominantColor.js';
|
||||
import { errCode } from '#lib/api/errors.js';
|
||||
import { qk } from '#lib/api/queries.js';
|
||||
@@ -77,12 +78,6 @@
|
||||
let starting = $state(false);
|
||||
let menuOpen = $state(false);
|
||||
|
||||
function toggleMenu(e: MouseEvent) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
menuOpen = !menuOpen;
|
||||
}
|
||||
|
||||
// Map PlaylistTrack rows to TrackRef shape and drop tracks whose
|
||||
// upstream file has been removed (track_id null).
|
||||
function toTrackRefs(rows: PlaylistTrack[]): TrackRef[] {
|
||||
@@ -167,7 +162,6 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onclick={() => { menuOpen = false; }} />
|
||||
|
||||
{#snippet kebab()}
|
||||
{#if refreshable}
|
||||
@@ -177,37 +171,22 @@
|
||||
class="kebab-wrap absolute right-1 top-1 z-10 transition-opacity duration-150
|
||||
{menuOpen ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 focus-within:opacity-100'}"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Playlist actions"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={menuOpen}
|
||||
onclick={toggleMenu}
|
||||
class="rounded p-1 text-text-muted hover:bg-surface-hover hover:text-text-primary"
|
||||
<KebabMenu
|
||||
label="Playlist actions"
|
||||
bind:open={menuOpen}
|
||||
width="w-44"
|
||||
triggerClass="rounded p-1 text-text-muted hover:bg-surface-hover hover:text-text-primary"
|
||||
>
|
||||
<MoreVertical size={16} strokeWidth={1} />
|
||||
</button>
|
||||
{#if menuOpen}
|
||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
||||
<!-- onclick is a stopPropagation guard against the window-level
|
||||
click-closes-menu pattern; not user-facing interaction. -->
|
||||
<div
|
||||
role="menu"
|
||||
tabindex="-1"
|
||||
class="absolute right-0 top-full z-20 mt-1 w-44 rounded-md border border-border bg-surface p-1 shadow-lg"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
onclick={onRefresh}
|
||||
class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm text-text-primary hover:bg-surface-hover"
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
role="menuitem"
|
||||
onclick={onRefresh}
|
||||
class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm text-text-primary hover:bg-surface-hover"
|
||||
>
|
||||
<RefreshCcw size={14} strokeWidth={1} />
|
||||
Refresh {playlist.name}
|
||||
</button>
|
||||
</div>
|
||||
{/if}
|
||||
<RefreshCcw size={14} strokeWidth={1} />
|
||||
Refresh {playlist.name}
|
||||
</button>
|
||||
</KebabMenu>
|
||||
</div>
|
||||
{/if}
|
||||
{/snippet}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
<script lang="ts" module>
|
||||
import type { ComponentType, SvelteComponent } from 'svelte';
|
||||
|
||||
type IconProp = ComponentType<SvelteComponent>;
|
||||
import type { IconProp } from './TrackMenuItem.svelte';
|
||||
|
||||
export interface RowAction {
|
||||
icon: IconProp;
|
||||
@@ -17,7 +15,7 @@
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
import { MoreVertical } from 'lucide-svelte';
|
||||
import KebabMenu from './KebabMenu.svelte';
|
||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||
|
||||
let {
|
||||
@@ -32,11 +30,6 @@
|
||||
|
||||
let menuOpen = $state(false);
|
||||
|
||||
function toggleMenu(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
menuOpen = !menuOpen;
|
||||
}
|
||||
|
||||
function fire(action: RowAction) {
|
||||
if (action.disabled) return;
|
||||
menuOpen = false;
|
||||
@@ -44,8 +37,6 @@
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onclick={() => { menuOpen = false; }} onkeydown={(e) => e.key === 'Escape' && (menuOpen = false)} />
|
||||
|
||||
<div class="flex items-center gap-2">
|
||||
<!-- Primary action: always inline -->
|
||||
<button
|
||||
@@ -82,39 +73,23 @@
|
||||
|
||||
<!-- Mobile overflow trigger -->
|
||||
{#if secondary.length > 0}
|
||||
<div class="relative md:hidden inline-block">
|
||||
<button
|
||||
type="button"
|
||||
aria-label="More actions"
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={menuOpen}
|
||||
onclick={toggleMenu}
|
||||
class="rounded p-1 text-text-secondary hover:text-text-primary
|
||||
min-h-[44px] min-w-[44px] flex items-center justify-center"
|
||||
>
|
||||
<MoreVertical size={18} strokeWidth={1} />
|
||||
</button>
|
||||
|
||||
{#if menuOpen}
|
||||
<div
|
||||
role="menu"
|
||||
tabindex="-1"
|
||||
class="absolute right-0 top-full z-20 mt-1 w-56 rounded-md border border-border
|
||||
bg-surface p-1 shadow-lg"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
onkeydown={(e) => e.stopPropagation()}
|
||||
>
|
||||
{#each secondary as action (action.label)}
|
||||
<TrackMenuItem
|
||||
icon={action.icon}
|
||||
label={action.label}
|
||||
onclick={() => fire(action)}
|
||||
danger={action.danger}
|
||||
disabled={action.disabled}
|
||||
/>
|
||||
{/each}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
<KebabMenu
|
||||
label="More actions"
|
||||
bind:open={menuOpen}
|
||||
class="md:hidden"
|
||||
iconSize={18}
|
||||
triggerClass="rounded p-1 text-text-secondary hover:text-text-primary
|
||||
min-h-[44px] min-w-[44px] flex items-center justify-center"
|
||||
>
|
||||
{#each secondary as action (action.label)}
|
||||
<TrackMenuItem
|
||||
icon={action.icon}
|
||||
label={action.label}
|
||||
onclick={() => fire(action)}
|
||||
danger={action.danger}
|
||||
disabled={action.disabled}
|
||||
/>
|
||||
{/each}
|
||||
</KebabMenu>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
<script lang="ts">
|
||||
import {
|
||||
MoreVertical,
|
||||
ListVideo,
|
||||
ListMusic,
|
||||
Heart,
|
||||
@@ -16,6 +15,7 @@
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
import FlagPopover from './FlagPopover.svelte';
|
||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
||||
import KebabMenu from './KebabMenu.svelte';
|
||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
||||
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
||||
@@ -59,11 +59,6 @@
|
||||
return rows.some((r) => r.track_id === track.id);
|
||||
});
|
||||
|
||||
function toggleMenu(e: MouseEvent) {
|
||||
e.stopPropagation();
|
||||
menuOpen = !menuOpen;
|
||||
}
|
||||
|
||||
function closeAll() {
|
||||
menuOpen = false;
|
||||
flagOpen = false;
|
||||
@@ -117,84 +112,64 @@
|
||||
goto(`/artists/${track.artist_id}`);
|
||||
}
|
||||
|
||||
function onKeydown(e: KeyboardEvent) {
|
||||
if (!menuOpen && !flagOpen && !addOpen) return;
|
||||
if (e.key === 'Escape') {
|
||||
e.preventDefault();
|
||||
closeAll();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onclick={() => { menuOpen = false; addOpen = false; }} onkeydown={onKeydown} />
|
||||
<KebabMenu
|
||||
label={`Track actions for ${track.title}`}
|
||||
bind:open={menuOpen}
|
||||
{direction}
|
||||
popoverOpen={flagOpen || addOpen}
|
||||
onclose={(why) => {
|
||||
addOpen = false;
|
||||
if (why === 'escape') flagOpen = false;
|
||||
}}
|
||||
>
|
||||
<!-- Item set + order mirror Android's canonical TrackActionsSheet so
|
||||
the kebab reads the same on both clients: queue group → like /
|
||||
add-to-playlist / start-radio group → navigation group → hide.
|
||||
"Start radio" is shown even under hideQueueActions (reseeding a
|
||||
station from the current track is meaningful where play-next /
|
||||
add-to-queue are not). No single-click destructive action lives
|
||||
here — track removal is intentionally kept out of the kebab. -->
|
||||
{#if !hideQueueActions}
|
||||
<TrackMenuItem icon={ListVideo} label="Play next" onclick={onPlayNext} />
|
||||
<TrackMenuItem icon={ListMusic} label="Add to queue" onclick={onAddToQueue} />
|
||||
|
||||
<div class="relative inline-block">
|
||||
<button
|
||||
type="button"
|
||||
aria-label={`Track actions for ${track.title}`}
|
||||
aria-haspopup="menu"
|
||||
aria-expanded={menuOpen}
|
||||
onclick={toggleMenu}
|
||||
class="rounded p-1 text-text-muted hover:text-text-primary"
|
||||
>
|
||||
<MoreVertical size={16} strokeWidth={1} />
|
||||
</button>
|
||||
|
||||
{#if menuOpen}
|
||||
<div
|
||||
role="menu"
|
||||
tabindex="-1"
|
||||
class="absolute right-0 z-20 w-56 rounded-md border border-border bg-surface p-1 shadow-lg
|
||||
{direction === 'up' ? 'bottom-full mb-1' : 'top-full mt-1'}"
|
||||
onclick={(e) => e.stopPropagation()}
|
||||
onkeydown={(e) => { e.stopPropagation(); if (e.key === 'Escape') menuOpen = false; }}
|
||||
>
|
||||
<!-- Item set + order mirror Android's canonical TrackActionsSheet so
|
||||
the kebab reads the same on both clients: queue group → like /
|
||||
add-to-playlist / start-radio group → navigation group → hide.
|
||||
"Start radio" is shown even under hideQueueActions (reseeding a
|
||||
station from the current track is meaningful where play-next /
|
||||
add-to-queue are not). No single-click destructive action lives
|
||||
here — track removal is intentionally kept out of the kebab. -->
|
||||
{#if !hideQueueActions}
|
||||
<TrackMenuItem icon={ListVideo} label="Play next" onclick={onPlayNext} />
|
||||
<TrackMenuItem icon={ListMusic} label="Add to queue" onclick={onAddToQueue} />
|
||||
|
||||
<TrackMenuDivider />
|
||||
{/if}
|
||||
|
||||
<TrackMenuItem
|
||||
icon={liked ? HeartOff : Heart}
|
||||
label={liked ? 'Unlike' : 'Like'}
|
||||
onclick={onToggleLike}
|
||||
/>
|
||||
<TrackMenuItem
|
||||
icon={ListPlus}
|
||||
label="Add to playlist…"
|
||||
onclick={() => { addOpen = true; menuOpen = false; }}
|
||||
/>
|
||||
<TrackMenuItem icon={Radio} label="Start radio" onclick={onStartRadio} />
|
||||
|
||||
<TrackMenuDivider />
|
||||
|
||||
<TrackMenuItem icon={Disc3} label="Go to album" onclick={onGoToAlbum} />
|
||||
<TrackMenuItem icon={User} label="Go to artist" onclick={onGoToArtist} />
|
||||
|
||||
<TrackMenuDivider />
|
||||
|
||||
<TrackMenuItem
|
||||
icon={hidden ? Eye : EyeOff}
|
||||
label={hidden ? 'Unhide' : 'Hide'}
|
||||
onclick={onToggleHide}
|
||||
/>
|
||||
</div>
|
||||
<TrackMenuDivider />
|
||||
{/if}
|
||||
|
||||
{#if flagOpen}
|
||||
<FlagPopover {track} {direction} onClose={closeAll} />
|
||||
{/if}
|
||||
<TrackMenuItem
|
||||
icon={liked ? HeartOff : Heart}
|
||||
label={liked ? 'Unlike' : 'Like'}
|
||||
onclick={onToggleLike}
|
||||
/>
|
||||
<TrackMenuItem
|
||||
icon={ListPlus}
|
||||
label="Add to playlist…"
|
||||
onclick={() => { addOpen = true; menuOpen = false; }}
|
||||
/>
|
||||
<TrackMenuItem icon={Radio} label="Start radio" onclick={onStartRadio} />
|
||||
|
||||
{#if addOpen}
|
||||
<AddToPlaylistMenu tracks={[track]} onClose={() => (addOpen = false)} />
|
||||
{/if}
|
||||
</div>
|
||||
<TrackMenuDivider />
|
||||
|
||||
<TrackMenuItem icon={Disc3} label="Go to album" onclick={onGoToAlbum} />
|
||||
<TrackMenuItem icon={User} label="Go to artist" onclick={onGoToArtist} />
|
||||
|
||||
<TrackMenuDivider />
|
||||
|
||||
<TrackMenuItem
|
||||
icon={hidden ? Eye : EyeOff}
|
||||
label={hidden ? 'Unhide' : 'Hide'}
|
||||
onclick={onToggleHide}
|
||||
/>
|
||||
|
||||
{#snippet after()}
|
||||
{#if flagOpen}
|
||||
<FlagPopover {track} {direction} onClose={closeAll} />
|
||||
{/if}
|
||||
|
||||
{#if addOpen}
|
||||
<AddToPlaylistMenu tracks={[track]} onClose={() => (addOpen = false)} />
|
||||
{/if}
|
||||
{/snippet}
|
||||
</KebabMenu>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<script lang="ts">
|
||||
<script lang="ts" module>
|
||||
import type { ComponentType, SvelteComponent } from 'svelte';
|
||||
|
||||
// Lucide-svelte ships class-based components (typeof ListPlus = ComponentType<...>),
|
||||
@@ -7,8 +7,10 @@
|
||||
// accepts size/strokeWidth as `string | number` and a tighter constraint
|
||||
// here trips structural assignment. We always pass numeric `size={14}` and
|
||||
// `strokeWidth={1}` below so the runtime contract is consistent.
|
||||
type IconProp = ComponentType<SvelteComponent>;
|
||||
export type IconProp = ComponentType<SvelteComponent>;
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
let {
|
||||
icon,
|
||||
label,
|
||||
|
||||
Reference in New Issue
Block a user