fix(web): clear the artist box after choosing, wrap suggestion cards on phones

Found in a real browser: after choosing a starting artist the box kept its text and claimed nothing matched, the card's buttons squeezed the name on a phone, and the switch knob was almost invisible when off.
This commit is contained in:
tgiachi 2026-11-12 14:15:51 +01:00
commit edbe212f46
4 changed files with 43 additions and 12 deletions

View file

@ -41,8 +41,8 @@ export default function ListeningSwitch() {
<span
aria-hidden="true"
className={cn(
'absolute top-0.5 left-0.5 size-5 rounded-sm bg-background transition-transform motion-reduce:transition-none',
on && 'translate-x-5',
'absolute top-0.5 left-0.5 size-5 rounded-sm transition-transform motion-reduce:transition-none',
on ? 'translate-x-5 bg-primary-foreground' : 'bg-muted-foreground',
)}
/>
</button>

View file

@ -54,9 +54,32 @@ test('typing finds artists, and choosing one makes it a chip', async () => {
await userEvent.click(await screen.findByRole('button', { name: 'Add Björk' }))
expect(calls.at(-1)?.url.searchParams.get('q')).toBe('bj')
expect(screen.getByRole('list', { name: 'Starting artists' })).toHaveTextContent('Björk')
// A chosen artist is not offered again.
await waitFor(() => expect(screen.queryByRole('button', { name: 'Add Björk' })).not.toBeInTheDocument())
expect(screen.getByRole('button', { name: 'Add Bjørn' })).toBeInTheDocument()
// Choosing is done: the box is empty for the next one and offers nothing.
expect(box()).toHaveValue('')
expect(screen.queryByRole('button', { name: 'Add Bjørn' })).not.toBeInTheDocument()
expect(screen.queryByText(/Nothing matches/)).not.toBeInTheDocument()
// Looking again, a chosen artist is not offered a second time.
await userEvent.type(box(), 'bj')
expect(await screen.findByRole('button', { name: 'Add Bjørn' })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Add Björk' })).not.toBeInTheDocument()
expect(screen.queryByText(/Nothing matches/)).not.toBeInTheDocument()
})
test('when the only match is already chosen it does not claim there is no match', async () => {
mockFetch({ 'GET /api/v1/artists': () => ({ items: [artist(1, 'Björk')], total: 1, limit: 6, offset: 0 }) })
renderPicker([{ id: 1, name: 'Björk' }])
await userEvent.type(box(), 'bj')
await waitFor(() => expect(box()).toHaveValue('bj'))
await new Promise((r) => setTimeout(r, 400))
expect(screen.queryByText(/Nothing matches/)).not.toBeInTheDocument()
})
test('a search that finds nothing says so', async () => {
mockFetch({ 'GET /api/v1/artists': () => ({ items: [], total: 0, limit: 6, offset: 0 }) })
renderPicker()
await userEvent.type(box(), 'zzz')
expect(await screen.findByText('Nothing matches “zzz”.')).toBeInTheDocument()
})
test('a chip can be taken away', async () => {

View file

@ -41,7 +41,15 @@ export default function SeedPicker({
const q = Array.from(typed.trim()).slice(0, MAX_QUERY_LENGTH).join('')
const found = useArtistList(q, { pageSize: SHOWN, enabled: q !== '' && !full })
const chosen = new Set(seeds.map((s) => s.id))
const offered = (found.data?.items ?? []).filter((a) => !chosen.has(a.id))
const matches = found.data?.items ?? []
const offered = matches.filter((a) => !chosen.has(a.id))
function choose(seed: Seed) {
onAdd(seed)
// Done with this one: the box is ready for the next.
setText('')
setTyped('')
}
return (
<div className="flex max-w-xl flex-col gap-3">
@ -73,7 +81,7 @@ export default function SeedPicker({
/>
{full && <p className="text-sm text-muted-foreground">{t('discover.seeds.max', { count: MAX_SEEDS })}</p>}
{!full && q !== '' && found.isSuccess && offered.length === 0 && <EmptyMessage>{t('empty.noMatch', { q })}</EmptyMessage>}
{!full && q !== '' && found.isSuccess && matches.length === 0 && <EmptyMessage>{t('empty.noMatch', { q })}</EmptyMessage>}
{offered.length > 0 && (
<ul className="flex flex-wrap gap-2">
{offered.map((artist) => (
@ -81,7 +89,7 @@ export default function SeedPicker({
<Button
variant="outline"
aria-label={t('discover.seeds.add', { name: artist.name })}
onClick={() => onAdd({ id: artist.id, name: artist.name })}
onClick={() => choose({ id: artist.id, name: artist.name })}
>
{artist.name}
</Button>

View file

@ -27,10 +27,10 @@ export default function SuggestionCard({ suggestion }: { suggestion: Suggestion
return (
<li className="flex flex-col gap-3 rounded-lg bg-card p-4 text-card-foreground">
<div className="flex items-center gap-4">
<div className="flex flex-wrap items-center gap-4">
<ArtistPhoto artistId={artist.id} name={artist.name} size={56} />
<div className="flex min-w-0 flex-1 flex-col">
<Link to={`/artists/${artist.id}`} className="truncate text-lg font-bold hover:underline">
<div className="flex min-w-40 flex-1 flex-col">
<Link to={`/artists/${artist.id}`} className="text-lg font-bold break-words hover:underline">
{artist.name}
</Link>
<div className="flex flex-wrap items-center gap-x-3 text-sm text-muted-foreground">
@ -38,7 +38,7 @@ export default function SuggestionCard({ suggestion }: { suggestion: Suggestion
{suggestion.in_library && <span>{t('discover.inLibrary')}</span>}
</div>
{suggestion.because.length > 0 && (
<p className="truncate text-sm text-muted-foreground">
<p className="text-sm break-words text-muted-foreground">
{t('discover.because', { names: suggestion.because.map((b) => b.artist.name).join(', ') })}
</p>
)}