refactor(web): every ⋮ menu shares one trigger and popover; album and artist menus are one (DRY W5)
release / web (push) Failing after 11s
release / go (push) Failing after 2m45s
release / govulncheck (push) Successful in 18s
release / integration (push) Failing after 4m51s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 2m12s
release / android (push) Canceled after 5m8s
release / web (push) Failing after 11s
release / go (push) Failing after 2m45s
release / govulncheck (push) Successful in 18s
release / integration (push) Failing after 4m51s
release / Attach APK to the Release (tag releases only) (push) Canceled after 0s
release / Build + push container image (push) Canceled after 0s
release / Verify release artifacts (tag releases only) (push) Canceled after 0s
release / Build signed APK (push) Canceled after 2m12s
release / android (push) Canceled after 5m8s
The ⋮ trigger, its popover and the close-on-outside-click and Escape handling were hand-rolled in AlbumMenu, ArtistMenu, TrackMenu, PlaylistCard and RowActionsMenu. KebabMenu now draws them once; each menu supplies its items and any popover it opens (Add to playlist, Report a problem). AlbumMenu and ArtistMenu were the same menu apart from their entity and "Go to artist"; both are now CollectionMenu with the entity filled in. Its track cache is kept per entity id, so a menu reused for another row fetches that row's tracks. Escape now also closes the playlist card's menu and the mobile row menu with focus inside it. IconProp is exported once, from TrackMenuItem (W10). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,145 +1,32 @@
|
|||||||
<script lang="ts">
|
<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 { listAlbumTracks } from '#lib/api/albums.js';
|
||||||
import { enqueueTracks } from '#lib/player/store.svelte.js';
|
import CollectionMenu from './CollectionMenu.svelte';
|
||||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
|
||||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
|
||||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
|
||||||
import type { TrackRef } from '#lib/api/types.js';
|
import type { TrackRef } from '#lib/api/types.js';
|
||||||
|
|
||||||
|
// An album's ⋮ menu: like, queue, add to playlist, go to artist.
|
||||||
let {
|
let {
|
||||||
albumId,
|
albumId,
|
||||||
albumTitle,
|
albumTitle,
|
||||||
artistId,
|
artistId,
|
||||||
artistName,
|
|
||||||
tracks,
|
tracks,
|
||||||
direction = 'down'
|
direction = 'down'
|
||||||
}: {
|
}: {
|
||||||
albumId: string;
|
albumId: string;
|
||||||
albumTitle: string;
|
albumTitle: string;
|
||||||
artistId: string;
|
artistId: string;
|
||||||
artistName: string;
|
artistName?: string;
|
||||||
|
/** Pre-loaded tracks; fetched on first use when omitted. */
|
||||||
tracks?: TrackRef[];
|
tracks?: TrackRef[];
|
||||||
direction?: 'up' | 'down';
|
direction?: 'up' | 'down';
|
||||||
} = $props();
|
} = $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>
|
</script>
|
||||||
|
|
||||||
<svelte:window onclick={() => { menuOpen = false; addOpen = false; }} onkeydown={onKeydown} />
|
<CollectionMenu
|
||||||
|
entity="album"
|
||||||
<div class="relative inline-block">
|
id={albumId}
|
||||||
<button
|
name={albumTitle}
|
||||||
type="button"
|
loadTracks={() => listAlbumTracks(albumId)}
|
||||||
aria-label={`Album actions for ${albumTitle}`}
|
{tracks}
|
||||||
aria-haspopup="menu"
|
{artistId}
|
||||||
aria-expanded={menuOpen}
|
{direction}
|
||||||
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>
|
|
||||||
|
|||||||
@@ -1,14 +1,9 @@
|
|||||||
<script lang="ts">
|
<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 { listArtistTracks } from '#lib/api/artists.js';
|
||||||
import { enqueueTracks } from '#lib/player/store.svelte.js';
|
import CollectionMenu from './CollectionMenu.svelte';
|
||||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
|
||||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
|
||||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
|
||||||
import type { TrackRef } from '#lib/api/types.js';
|
import type { TrackRef } from '#lib/api/types.js';
|
||||||
|
|
||||||
|
// An artist's ⋮ menu: like, and queue or add to a playlist all their tracks.
|
||||||
let {
|
let {
|
||||||
artistId,
|
artistId,
|
||||||
artistName,
|
artistName,
|
||||||
@@ -17,116 +12,17 @@
|
|||||||
}: {
|
}: {
|
||||||
artistId: string;
|
artistId: string;
|
||||||
artistName: 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[];
|
tracks?: TrackRef[];
|
||||||
/** Open above the trigger when used near the bottom of the viewport. */
|
|
||||||
direction?: 'up' | 'down';
|
direction?: 'up' | 'down';
|
||||||
} = $props();
|
} = $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>
|
</script>
|
||||||
|
|
||||||
<svelte:window onclick={() => { menuOpen = false; addOpen = false; }} onkeydown={onKeydown} />
|
<CollectionMenu
|
||||||
|
entity="artist"
|
||||||
<div class="relative inline-block">
|
id={artistId}
|
||||||
<button
|
name={artistName}
|
||||||
type="button"
|
loadTracks={() => listArtistTracks(artistId)}
|
||||||
aria-label={`Artist actions for ${artistName}`}
|
{tracks}
|
||||||
aria-haspopup="menu"
|
{direction}
|
||||||
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>
|
|
||||||
|
|||||||
@@ -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">
|
<script lang="ts">
|
||||||
import { plural } from '#lib/utils/plural.js';
|
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 { useQueryClient } from '@tanstack/svelte-query';
|
||||||
import type { Playlist, PlaylistTrack, TrackRef } from '#lib/api/types.js';
|
import type { Playlist, PlaylistTrack, TrackRef } from '#lib/api/types.js';
|
||||||
import { user } from '#lib/auth/store.svelte.js';
|
import { user } from '#lib/auth/store.svelte.js';
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
import { refreshedLabel, songsLikeArtist, washTone } from '#lib/playlists/shelf.js';
|
import { refreshedLabel, songsLikeArtist, washTone } from '#lib/playlists/shelf.js';
|
||||||
import { coverUrl } from '#lib/media/covers.js';
|
import { coverUrl } from '#lib/media/covers.js';
|
||||||
import Cover from './Cover.svelte';
|
import Cover from './Cover.svelte';
|
||||||
|
import KebabMenu from './KebabMenu.svelte';
|
||||||
import { dominantColorFromUrl, rgbToCssString } from '#lib/media/dominantColor.js';
|
import { dominantColorFromUrl, rgbToCssString } from '#lib/media/dominantColor.js';
|
||||||
import { errCode } from '#lib/api/errors.js';
|
import { errCode } from '#lib/api/errors.js';
|
||||||
import { qk } from '#lib/api/queries.js';
|
import { qk } from '#lib/api/queries.js';
|
||||||
@@ -77,12 +78,6 @@
|
|||||||
let starting = $state(false);
|
let starting = $state(false);
|
||||||
let menuOpen = $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
|
// Map PlaylistTrack rows to TrackRef shape and drop tracks whose
|
||||||
// upstream file has been removed (track_id null).
|
// upstream file has been removed (track_id null).
|
||||||
function toTrackRefs(rows: PlaylistTrack[]): TrackRef[] {
|
function toTrackRefs(rows: PlaylistTrack[]): TrackRef[] {
|
||||||
@@ -167,7 +162,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window onclick={() => { menuOpen = false; }} />
|
|
||||||
|
|
||||||
{#snippet kebab()}
|
{#snippet kebab()}
|
||||||
{#if refreshable}
|
{#if refreshable}
|
||||||
@@ -177,37 +171,22 @@
|
|||||||
class="kebab-wrap absolute right-1 top-1 z-10 transition-opacity duration-150
|
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'}"
|
{menuOpen ? 'opacity-100' : 'opacity-0 group-hover:opacity-100 focus-within:opacity-100'}"
|
||||||
>
|
>
|
||||||
<button
|
<KebabMenu
|
||||||
type="button"
|
label="Playlist actions"
|
||||||
aria-label="Playlist actions"
|
bind:open={menuOpen}
|
||||||
aria-haspopup="menu"
|
width="w-44"
|
||||||
aria-expanded={menuOpen}
|
triggerClass="rounded p-1 text-text-muted hover:bg-surface-hover hover:text-text-primary"
|
||||||
onclick={toggleMenu}
|
|
||||||
class="rounded p-1 text-text-muted hover:bg-surface-hover hover:text-text-primary"
|
|
||||||
>
|
>
|
||||||
<MoreVertical size={16} strokeWidth={1} />
|
<button
|
||||||
</button>
|
type="button"
|
||||||
{#if menuOpen}
|
role="menuitem"
|
||||||
<!-- svelte-ignore a11y_click_events_have_key_events -->
|
onclick={onRefresh}
|
||||||
<!-- onclick is a stopPropagation guard against the window-level
|
class="flex w-full items-center gap-2 rounded px-2 py-1.5 text-sm text-text-primary hover:bg-surface-hover"
|
||||||
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
|
<RefreshCcw size={14} strokeWidth={1} />
|
||||||
type="button"
|
Refresh {playlist.name}
|
||||||
role="menuitem"
|
</button>
|
||||||
onclick={onRefresh}
|
</KebabMenu>
|
||||||
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}
|
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
{/snippet}
|
{/snippet}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
<script lang="ts" module>
|
<script lang="ts" module>
|
||||||
import type { ComponentType, SvelteComponent } from 'svelte';
|
import type { IconProp } from './TrackMenuItem.svelte';
|
||||||
|
|
||||||
type IconProp = ComponentType<SvelteComponent>;
|
|
||||||
|
|
||||||
export interface RowAction {
|
export interface RowAction {
|
||||||
icon: IconProp;
|
icon: IconProp;
|
||||||
@@ -17,7 +15,7 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { MoreVertical } from 'lucide-svelte';
|
import KebabMenu from './KebabMenu.svelte';
|
||||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||||
|
|
||||||
let {
|
let {
|
||||||
@@ -32,11 +30,6 @@
|
|||||||
|
|
||||||
let menuOpen = $state(false);
|
let menuOpen = $state(false);
|
||||||
|
|
||||||
function toggleMenu(e: MouseEvent) {
|
|
||||||
e.stopPropagation();
|
|
||||||
menuOpen = !menuOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
function fire(action: RowAction) {
|
function fire(action: RowAction) {
|
||||||
if (action.disabled) return;
|
if (action.disabled) return;
|
||||||
menuOpen = false;
|
menuOpen = false;
|
||||||
@@ -44,8 +37,6 @@
|
|||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:window onclick={() => { menuOpen = false; }} onkeydown={(e) => e.key === 'Escape' && (menuOpen = false)} />
|
|
||||||
|
|
||||||
<div class="flex items-center gap-2">
|
<div class="flex items-center gap-2">
|
||||||
<!-- Primary action: always inline -->
|
<!-- Primary action: always inline -->
|
||||||
<button
|
<button
|
||||||
@@ -82,39 +73,23 @@
|
|||||||
|
|
||||||
<!-- Mobile overflow trigger -->
|
<!-- Mobile overflow trigger -->
|
||||||
{#if secondary.length > 0}
|
{#if secondary.length > 0}
|
||||||
<div class="relative md:hidden inline-block">
|
<KebabMenu
|
||||||
<button
|
label="More actions"
|
||||||
type="button"
|
bind:open={menuOpen}
|
||||||
aria-label="More actions"
|
class="md:hidden"
|
||||||
aria-haspopup="menu"
|
iconSize={18}
|
||||||
aria-expanded={menuOpen}
|
triggerClass="rounded p-1 text-text-secondary hover:text-text-primary
|
||||||
onclick={toggleMenu}
|
min-h-[44px] min-w-[44px] flex items-center justify-center"
|
||||||
class="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
|
||||||
<MoreVertical size={18} strokeWidth={1} />
|
icon={action.icon}
|
||||||
</button>
|
label={action.label}
|
||||||
|
onclick={() => fire(action)}
|
||||||
{#if menuOpen}
|
danger={action.danger}
|
||||||
<div
|
disabled={action.disabled}
|
||||||
role="menu"
|
/>
|
||||||
tabindex="-1"
|
{/each}
|
||||||
class="absolute right-0 top-full z-20 mt-1 w-56 rounded-md border border-border
|
</KebabMenu>
|
||||||
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>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import {
|
import {
|
||||||
MoreVertical,
|
|
||||||
ListVideo,
|
ListVideo,
|
||||||
ListMusic,
|
ListMusic,
|
||||||
Heart,
|
Heart,
|
||||||
@@ -16,6 +15,7 @@
|
|||||||
import { useQueryClient } from '@tanstack/svelte-query';
|
import { useQueryClient } from '@tanstack/svelte-query';
|
||||||
import FlagPopover from './FlagPopover.svelte';
|
import FlagPopover from './FlagPopover.svelte';
|
||||||
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
|
||||||
|
import KebabMenu from './KebabMenu.svelte';
|
||||||
import TrackMenuItem from './TrackMenuItem.svelte';
|
import TrackMenuItem from './TrackMenuItem.svelte';
|
||||||
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
import TrackMenuDivider from './TrackMenuDivider.svelte';
|
||||||
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
import { createLikedIdsQuery, likeEntity, unlikeEntity } from '#lib/api/likes.js';
|
||||||
@@ -59,11 +59,6 @@
|
|||||||
return rows.some((r) => r.track_id === track.id);
|
return rows.some((r) => r.track_id === track.id);
|
||||||
});
|
});
|
||||||
|
|
||||||
function toggleMenu(e: MouseEvent) {
|
|
||||||
e.stopPropagation();
|
|
||||||
menuOpen = !menuOpen;
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeAll() {
|
function closeAll() {
|
||||||
menuOpen = false;
|
menuOpen = false;
|
||||||
flagOpen = false;
|
flagOpen = false;
|
||||||
@@ -117,84 +112,64 @@
|
|||||||
goto(`/artists/${track.artist_id}`);
|
goto(`/artists/${track.artist_id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onKeydown(e: KeyboardEvent) {
|
|
||||||
if (!menuOpen && !flagOpen && !addOpen) return;
|
|
||||||
if (e.key === 'Escape') {
|
|
||||||
e.preventDefault();
|
|
||||||
closeAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</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">
|
<TrackMenuDivider />
|
||||||
<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>
|
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if flagOpen}
|
<TrackMenuItem
|
||||||
<FlagPopover {track} {direction} onClose={closeAll} />
|
icon={liked ? HeartOff : Heart}
|
||||||
{/if}
|
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}
|
<TrackMenuDivider />
|
||||||
<AddToPlaylistMenu tracks={[track]} onClose={() => (addOpen = false)} />
|
|
||||||
{/if}
|
<TrackMenuItem icon={Disc3} label="Go to album" onclick={onGoToAlbum} />
|
||||||
</div>
|
<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';
|
import type { ComponentType, SvelteComponent } from 'svelte';
|
||||||
|
|
||||||
// Lucide-svelte ships class-based components (typeof ListPlus = ComponentType<...>),
|
// Lucide-svelte ships class-based components (typeof ListPlus = ComponentType<...>),
|
||||||
@@ -7,8 +7,10 @@
|
|||||||
// accepts size/strokeWidth as `string | number` and a tighter constraint
|
// accepts size/strokeWidth as `string | number` and a tighter constraint
|
||||||
// here trips structural assignment. We always pass numeric `size={14}` and
|
// here trips structural assignment. We always pass numeric `size={14}` and
|
||||||
// `strokeWidth={1}` below so the runtime contract is consistent.
|
// `strokeWidth={1}` below so the runtime contract is consistent.
|
||||||
type IconProp = ComponentType<SvelteComponent>;
|
export type IconProp = ComponentType<SvelteComponent>;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
let {
|
let {
|
||||||
icon,
|
icon,
|
||||||
label,
|
label,
|
||||||
|
|||||||
Reference in New Issue
Block a user