Android played the visible search results as a queue; the web started radio. Both now start radio seeded from the tapped track: the song plays first, then songs like it. Android falls back to playing the track alone when radio can't be had (offline, or an empty answer). The web's two identical onTrackPlay handlers (search and search/tracks) become one, radioFromRow. PlayerController gains playRadio, which replaces the queue; the track menu's startRadio still keeps the current song playing and queues radio after it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.4 KiB
Svelte
59 lines
2.4 KiB
Svelte
<script lang="ts">
|
|
import { plural } from '#lib/utils/plural.js';
|
|
import PageColumn from '#lib/components/PageColumn.svelte';
|
|
import { pageTitle } from '#lib/branding.js';
|
|
import { page } from '$app/state';
|
|
import { createSearchTracksInfiniteQuery } from '#lib/api/queries.js';
|
|
import TrackRow from '#lib/components/TrackRow.svelte';
|
|
import TrackList from '#lib/components/TrackList.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';
|
|
import { radioFromRow } from '#lib/player/radioFromRow.js';
|
|
|
|
const q = $derived((page.url.searchParams.get('q') ?? '').trim());
|
|
const queryStore = $derived(q ? createSearchTracksInfiniteQuery(q) : null);
|
|
const query = $derived(queryStore ? $queryStore : null);
|
|
|
|
const tracks = $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 · Tracks')}</title></svelte:head>
|
|
|
|
<PageColumn>
|
|
<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 font-display text-2xl font-medium text-text-primary">Tracks matching '{q}'</h1>
|
|
{#if q && !query?.isPending && !(query?.isError && tracks.length === 0)}
|
|
<p class="text-sm text-text-secondary">{plural(total, 'track', 'tracks')}</p>
|
|
{/if}
|
|
</header>
|
|
|
|
{#if !q}
|
|
<p class="text-text-secondary">No query — return to search to start typing.</p>
|
|
{:else if query?.isError && tracks.length === 0}
|
|
<ApiErrorBanner error={query.error} onRetry={query.refetch} />
|
|
{:else if showSkeleton.value && tracks.length === 0}
|
|
<LibrarySkeleton variant="list" count={12} />
|
|
{:else if total === 0}
|
|
<p class="text-text-secondary">No track matches.</p>
|
|
{:else}
|
|
<TrackList>
|
|
{#each tracks as t, i (t.id)}
|
|
<TrackRow tracks={tracks} index={i} onPlay={radioFromRow} />
|
|
{/each}
|
|
</TrackList>
|
|
<ListContinuation
|
|
hasMore={!!query?.hasNextPage}
|
|
loading={!!query?.isFetchingNextPage}
|
|
failed={!!query?.isFetchNextPageError}
|
|
onMore={() => query?.fetchNextPage()}
|
|
/>
|
|
{/if}
|
|
</PageColumn>
|