Files
minstrel/web/src/lib/components/AlbumMenu.svelte
T
bvandeusenandClaude Opus 5.5 94a9c8cbe3 chore(deps): SvelteKit 3 with adapter-static 4 and TypeScript 6, full-tree npm audit (#5021)
Merges Renovate's kit 3 (PR #149) and adapter-static 4 (PR #148) bumps,
plus the migration they need. The mechanical part is `sv migrate
sveltekit-3`, run one task at a time and reviewed:

- svelte.config.js is gone. Its options move into sveltekit() in
  vite.config.ts, exported as kitOptions so vitest.config.ts runs the
  same kit setup, including the $test-utils alias the tests import.
- $lib becomes #lib through package.json "imports". There is no
  src/lib/index, so only the "#lib/*" entry is kept.
- tsconfig extends $app/tsconfig.
- Peer floors raised to kit 3's requirements: svelte ^5.57.1, vite
  ^8.0.12, svelte-check ^4.7.5.

By hand, from the codemod's list of non-automated tasks:

- goto's replaceState option is now replace; keepFocus becomes
  reset: false. For the search typeahead, reset: false also stops the
  scroll-to-top, which is wanted while typing.
- The test setup mocks drop pushState/replaceState and $app/paths
  base/assets, which kit 3 removed, and mock refreshAll in place of
  invalidateAll.
- The other flagged files only read page.url or goto internal routes,
  so they needed no change.

TypeScript goes to ^6, not the ^7 Renovate offers: kit 3 declares
typescript ^6 as a peer and svelte-check 4.7 accepts ^5 || ^6. Move to
7 once both accept it.

With Tailwind 4 and kit 3 in, `npm audit` on the whole tree reports 0,
so the web lane now audits every dependency rather than only what
ships to browsers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 10:50:39 -04:00

146 lines
4.3 KiB
Svelte

<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 type { TrackRef } from '#lib/api/types.js';
let {
albumId,
albumTitle,
artistId,
artistName,
tracks,
direction = 'down'
}: {
albumId: string;
albumTitle: string;
artistId: string;
artistName: string;
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>