feat: tapping a search result starts radio from that track, on web and Android (DRY A3)

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>
This commit is contained in:
2026-11-27 10:16:40 -05:00
co-authored by Claude Opus 5.5
parent ebb8e331a2
commit d5d9952cd7
5 changed files with 56 additions and 26 deletions
+14
View File
@@ -0,0 +1,14 @@
import { playRadio } from './store.svelte';
import type { TrackRef } from '#lib/api/types.js';
/**
* A track row's play handler that starts radio seeded from the tapped
* track, rather than playing the list it sits in. Search results use it:
* a list of matches for a few typed words is rarely what someone wants to
* hear next, and radio plays the tapped song first, then songs like it.
* Android's search does the same (SearchViewModel.playTrack).
*/
export function radioFromRow(tracks: TrackRef[], index: number): void {
const track = tracks[index];
if (track) void playRadio(track.id);
}
+2 -7
View File
@@ -9,8 +9,7 @@
import SearchSkeleton from '#lib/components/SearchSkeleton.svelte';
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
import { useDelayed } from '#lib/utils/useDelayed.svelte.js';
import { playRadio } from '#lib/player/store.svelte.js';
import type { TrackRef } from '#lib/api/types.js';
import { radioFromRow } from '#lib/player/radioFromRow.js';
const q = $derived((page.url.searchParams.get('q') ?? '').trim());
const queryStore = $derived(q ? createSearchQuery(q) : null);
@@ -28,10 +27,6 @@
);
const showSkeleton = useDelayed(() => !!query?.isPending);
function onTrackPlay(_tracks: TrackRef[], index: number) {
playRadio(_tracks[index].id);
}
</script>
<svelte:head><title>{pageTitle('Search')}</title></svelte:head>
@@ -107,7 +102,7 @@
</header>
<TrackList>
{#each tracks.items as t, i (t.id)}
<TrackRow tracks={tracks.items} index={i} onPlay={onTrackPlay} />
<TrackRow tracks={tracks.items} index={i} onPlay={radioFromRow} />
{/each}
</TrackList>
</section>
+2 -7
View File
@@ -10,8 +10,7 @@
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
import ListContinuation from '#lib/components/ListContinuation.svelte';
import { useDelayed } from '#lib/utils/useDelayed.svelte.js';
import { playRadio } from '#lib/player/store.svelte.js';
import type { TrackRef } from '#lib/api/types.js';
import { radioFromRow } from '#lib/player/radioFromRow.js';
const q = $derived((page.url.searchParams.get('q') ?? '').trim());
const queryStore = $derived(q ? createSearchTracksInfiniteQuery(q) : null);
@@ -20,10 +19,6 @@
const tracks = $derived(query?.data?.pages?.flatMap((p) => p.items) ?? []);
const total = $derived(query?.data?.pages?.[0]?.total ?? 0);
const showSkeleton = useDelayed(() => !!query?.isPending);
function onTrackPlay(_tracks: TrackRef[], index: number) {
playRadio(_tracks[index].id);
}
</script>
<svelte:head><title>{pageTitle('Search · Tracks')}</title></svelte:head>
@@ -50,7 +45,7 @@
{:else}
<TrackList>
{#each tracks as t, i (t.id)}
<TrackRow tracks={tracks} index={i} onPlay={onTrackPlay} />
<TrackRow tracks={tracks} index={i} onPlay={radioFromRow} />
{/each}
</TrackList>
<ListContinuation