Files
minstrel/web/src/lib/components/SelectionBar.svelte
T
bvandeusenandClaude Opus 5.5 be384c8efe
release / go (push) Failing after 1m10s
release / web (push) Failing after 10s
release / android (push) Failing after 1m2s
release / govulncheck (push) Successful in 17s
release / integration (push) Successful in 2m31s
release / Build signed APK (push) Failing after 1m43s
release / Build + push container image (push) Skipped
web: svelte-query 6 — queries are reactive objects read directly, not stores (#8532)
@tanstack/svelte-query 6 is built on runes:
- createQuery and createInfiniteQuery take their options as a function
  and return a reactive object that components read as query.data.
- createMutation takes its options the same way.

What this commit changes:
- Every query creator in src/lib/api now takes its arguments as getters
  and reads them inside the options, so a query follows the values it
  depends on. Before, each component rebuilt it in a $derived.
- Constant arguments are passed as getters too, so the rule has no
  exceptions.
- Components call a creator once at init: const query =
  createArtistQuery(() => id). The $derived(create…) and $store pairs
  are gone.
- A query that loads only on demand (a chosen genre or year, the
  Handled view) has an enabled getter. The page keeps its `cond ? q :
  null` alias, because a switched-off query reports isPending and the
  page expects null when nothing is chosen.
- Tests: the query mocks return plain objects. liveQuery
  (test-utils/liveQuery.svelte.ts) gives a test a result it can change
  mid-test. Argument checks call the getter the page passed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-04 10:55:05 -05:00

130 lines
4.2 KiB
Svelte
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script lang="ts">
import { X, ListPlus, Plus, ListMusic, Heart } from '@lucide/svelte';
import { useQueryClient } from '@tanstack/svelte-query';
import { selection, clearSelection } from '#lib/selection/store.svelte.js';
import { playNextMany, enqueueTracks } from '#lib/player/store.svelte.js';
import { likeEntity, createLikedIdsQuery } from '#lib/api/likes.js';
import AddToPlaylistMenu from './AddToPlaylistMenu.svelte';
const queryClient = useQueryClient();
const likedQ = createLikedIdsQuery();
const likedIds = $derived(likedQ.data?.track_ids ?? []);
let addOpen = $state(false);
let busy = $state(false);
function onPlayNext() {
playNextMany(selection.tracks);
clearSelection();
}
function onAddQueue() {
enqueueTracks(selection.tracks);
clearSelection();
}
async function onLikeAll() {
if (busy) return;
busy = true;
try {
const likedSet = new Set(likedIds);
const toLike = selection.tracks.filter((t) => !likedSet.has(t.id));
for (const t of toLike) {
await likeEntity(queryClient, 'track', t.id);
}
clearSelection();
} finally {
busy = false;
}
}
function onClose() {
addOpen = false;
}
</script>
{#if selection.active}
<!-- Sits above PlayerBar (z-30 < 40). Anchors to the viewport bottom
with bottom-24 so PlayerBar's ~80px shell stays visible. The bar
is dismissed by the × button or by Escape (handled in layout). -->
<div
role="region"
aria-label="Selection actions"
class="pointer-events-none fixed inset-x-0 bottom-24 z-30 flex justify-center px-4"
>
<div
class="pointer-events-auto flex items-center gap-2 rounded-full border border-border
bg-surface px-3 py-2 shadow-lg"
>
<span class="px-2 text-sm text-text-primary">
{selection.count} selected
</span>
<span class="h-5 w-px bg-border"></span>
<button
type="button"
onclick={onPlayNext}
aria-label="Play selected next"
title="Play next"
class="flex items-center gap-1.5 rounded px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent"
>
<ListPlus size={16} strokeWidth={1.5} />
<span class="hidden sm:inline">Play next</span>
</button>
<button
type="button"
onclick={onAddQueue}
aria-label="Add selected to queue"
title="Add to queue"
class="flex items-center gap-1.5 rounded px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent"
>
<Plus size={16} strokeWidth={1.5} />
<span class="hidden sm:inline">Add to queue</span>
</button>
<button
type="button"
onclick={() => (addOpen = !addOpen)}
aria-haspopup="menu"
aria-expanded={addOpen}
aria-label="Add selected to playlist"
title="Add to playlist"
class="flex items-center gap-1.5 rounded px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent"
>
<ListMusic size={16} strokeWidth={1.5} />
<span class="hidden sm:inline">Add to playlist</span>
</button>
<button
type="button"
onclick={onLikeAll}
disabled={busy}
aria-label="Like all selected"
title="Like all"
class="flex items-center gap-1.5 rounded px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-50"
>
<Heart size={16} strokeWidth={1.5} />
<span class="hidden sm:inline">Like all</span>
</button>
<span class="h-5 w-px bg-border"></span>
<button
type="button"
onclick={clearSelection}
aria-label="Clear selection"
title="Clear selection"
class="rounded p-1.5 text-text-secondary hover:text-text-primary focus-visible:ring-2 focus-visible:ring-accent"
>
<X size={16} strokeWidth={1.5} />
</button>
</div>
{#if addOpen}
<div class="pointer-events-auto absolute bottom-full mb-2">
<AddToPlaylistMenu tracks={selection.tracks} {onClose} />
</div>
{/if}
</div>
{/if}