Files
minstrel/web/src/routes/search/artists/+page.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

56 lines
2.2 KiB
Svelte

<script lang="ts">
import { plural } from '#lib/utils/plural.js';
import { pageTitle } from '#lib/branding.js';
import { page } from '$app/state';
import { createSearchArtistsInfiniteQuery } from '#lib/api/queries.js';
import ArtistCard from '#lib/components/ArtistCard.svelte';
import LibrarySkeleton from '#lib/components/LibrarySkeleton.svelte';
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
import ListContinuation from '#lib/components/ListContinuation.svelte';
import { useDelayed } from '#lib/utils/useDelayed.svelte.js';
const q = $derived((page.url.searchParams.get('q') ?? '').trim());
const artistsQ = createSearchArtistsInfiniteQuery(() => q);
const query = $derived(q ? artistsQ : null);
const artists = $derived(query?.data?.pages?.flatMap((p) => p.items) ?? []);
const total = $derived(query?.data?.pages?.[0]?.total ?? 0);
const showSkeleton = useDelayed(() => !!query?.isPending);
</script>
<svelte:head><title>{pageTitle('Search · Artists')}</title></svelte:head>
<div class="space-y-4">
<header>
<a href={`/search?q=${encodeURIComponent(q)}`} class="text-sm text-text-secondary hover:text-text-primary">
← Back to search
</a>
<h1 class="mt-2 text-2xl font-semibold">Artists matching '{q}'</h1>
{#if q && !query?.isPending && !(query?.isError && artists.length === 0)}
<p class="text-sm text-text-secondary">{plural(total, 'artist', 'artists')}</p>
{/if}
</header>
{#if !q}
<p class="text-text-secondary">No query — return to search to start typing.</p>
{:else if query?.isError && artists.length === 0}
<ApiErrorBanner error={query.error} onRetry={query.refetch} />
{:else if showSkeleton.value && artists.length === 0}
<LibrarySkeleton variant="list" count={12} />
{:else if total === 0}
<p class="text-text-secondary">No artist matches.</p>
{:else}
<div class="grid grid-cols-2 gap-4 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5">
{#each artists as a (a.id)}
<ArtistCard artist={a} />
{/each}
</div>
<ListContinuation
hasMore={!!query?.hasNextPage}
loading={!!query?.isFetchingNextPage}
failed={!!query?.isFetchNextPageError}
onMore={() => query?.fetchNextPage()}
/>
{/if}
</div>