+ )
+}
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index 300707c..a57db21 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -58,6 +58,17 @@
"currentPasswordWrong": "The current password is wrong.",
"changePassword": "Change password"
},
+ "discover": {
+ "title": "Discover",
+ "listening": {
+ "label": "Start Discover from my listening",
+ "help": "When this is on, the names of the artists you play most go to Last.fm, if an admin turned Last.fm on, to find similar artists. When it is off, Discover starts only from artists you pick.",
+ "confirmTitle": "Send your top artists to Last.fm?",
+ "confirmBody": "Discover will send the names of the artists you play most to Last.fm, if an admin turned Last.fm on, and ask for similar artists. Nothing else about you is sent. You can turn this off at any time.",
+ "turnOn": "Turn on",
+ "cancel": "Cancel"
+ }
+ },
"home": {
"greeting_morning": "Good morning",
"greeting_afternoon": "Good afternoon",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index 86c7c62..27281ef 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -58,6 +58,17 @@
"currentPasswordWrong": "La password attuale è sbagliata.",
"changePassword": "Cambia password"
},
+ "discover": {
+ "title": "Discover",
+ "listening": {
+ "label": "Avvia Discover dai miei ascolti",
+ "help": "Se è acceso, i nomi degli artisti che ascolti di più vanno a Last.fm, se un admin l'ha acceso, per trovare artisti simili. Se è spento, Discover parte solo dagli artisti che scegli tu.",
+ "confirmTitle": "Mandare i tuoi artisti preferiti a Last.fm?",
+ "confirmBody": "Discover manderà a Last.fm i nomi degli artisti che ascolti di più, se un admin ha acceso Last.fm, e chiederà artisti simili. Non viene mandato nient'altro su di te. Puoi spegnerlo quando vuoi.",
+ "turnOn": "Accendi",
+ "cancel": "Annulla"
+ }
+ },
"home": {
"greeting_morning": "Buongiorno",
"greeting_afternoon": "Buon pomeriggio",
diff --git a/web/src/pages/SettingsPage.test.tsx b/web/src/pages/SettingsPage.test.tsx
index db500ab..75018db 100644
--- a/web/src/pages/SettingsPage.test.tsx
+++ b/web/src/pages/SettingsPage.test.tsx
@@ -1,3 +1,4 @@
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MemoryRouter } from 'react-router-dom'
@@ -12,14 +13,18 @@ import SettingsPage from './SettingsPage'
const noContent = () => new Response(null, { status: 204 })
function renderSettings() {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
return render(
-
-
- ,
+
+
+
+
+ ,
)
}
beforeEach(async () => {
+ mockFetch({ 'GET /api/v1/me/settings': () => ({ discover_from_listening: false }) })
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
await initI18n()
initTheme()
@@ -93,12 +98,19 @@ test('choosing Italian changes the words on the page', async () => {
expect(localStorage.getItem('sonda.lang')).toBe('it')
})
+test('Discover has its own group with the switch for using your listening, off until you turn it on', async () => {
+ renderSettings()
+ expect(screen.getByRole('region', { name: 'Discover' })).toBeInTheDocument()
+ const sw = await screen.findByRole('switch', { name: 'Start Discover from my listening' })
+ expect(sw).toHaveAttribute('aria-checked', 'false')
+})
+
test('a new password of seven characters is refused here, with no request', async () => {
const { calls } = mockFetch({})
renderSettings()
await changePassword('old-password', '1234567')
expect(await screen.findByRole('alert')).toHaveTextContent('The new password needs 8 to 256 characters.')
- expect(calls).toHaveLength(0)
+ expect(calls.filter((c) => c.url.pathname === '/api/v1/auth/password')).toHaveLength(0)
})
test('a new password longer than 256 bytes is refused here, with no request', async () => {
@@ -109,7 +121,7 @@ test('a new password longer than 256 bytes is refused here, with no request', as
await userEvent.paste('x'.repeat(257))
await userEvent.click(screen.getByRole('button', { name: 'Change password' }))
expect(await screen.findByRole('alert')).toHaveTextContent('8 to 256')
- expect(calls).toHaveLength(0)
+ expect(calls.filter((c) => c.url.pathname === '/api/v1/auth/password')).toHaveLength(0)
})
test('a changed password signs this session out, because the server ends every session', async () => {
diff --git a/web/src/pages/SettingsPage.tsx b/web/src/pages/SettingsPage.tsx
index 00f355e..1b670b3 100644
--- a/web/src/pages/SettingsPage.tsx
+++ b/web/src/pages/SettingsPage.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'
import { api, ApiError } from '@/api/client'
import { logout, useSession } from '@/auth/session'
import ChoiceGroup from '@/components/ChoiceGroup'
+import ListeningSwitch from '@/components/ListeningSwitch'
import Section from '@/components/Section'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
@@ -136,6 +137,10 @@ export default function SettingsPage() {
/>
+
+
+
+
From 71b0b39a0772dd23de141e35a46e782f22eb925d Mon Sep 17 00:00:00 2001
From: tgiachi
Date: Thu, 12 Nov 2026 14:06:49 +0100
Subject: [PATCH 04/10] feat(web): a card for a Discover suggestion with its
score explained
Shows the score in percent, the seeds it comes from, a part-by-part explanation (a missing genre is not a zero), and the wishlist and not-interested actions.
---
web/src/i18n/locales/en.json | 14 +++
web/src/i18n/locales/it.json | 14 +++
.../pages/discover/SuggestionCard.test.tsx | 110 ++++++++++++++++++
web/src/pages/discover/SuggestionCard.tsx | 77 ++++++++++++
4 files changed, 215 insertions(+)
create mode 100644 web/src/pages/discover/SuggestionCard.test.tsx
create mode 100644 web/src/pages/discover/SuggestionCard.tsx
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index a57db21..1674534 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -60,6 +60,20 @@
},
"discover": {
"title": "Discover",
+ "score": "{{percent}}% match",
+ "because": "Because of {{names}}",
+ "inLibrary": "In your library",
+ "why": "Why this?",
+ "wishlist": "Wishlist",
+ "notInterested": "Not interested",
+ "parts": {
+ "label": "How the score is made",
+ "a": "Similar to your starting artists",
+ "g": "Genres close to your taste",
+ "p": "What you play",
+ "d": "Not played yet",
+ "noGenre": "No genre data"
+ },
"listening": {
"label": "Start Discover from my listening",
"help": "When this is on, the names of the artists you play most go to Last.fm, if an admin turned Last.fm on, to find similar artists. When it is off, Discover starts only from artists you pick.",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index 27281ef..9b31471 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -60,6 +60,20 @@
},
"discover": {
"title": "Discover",
+ "score": "{{percent}}% di affinità",
+ "because": "Per via di {{names}}",
+ "inLibrary": "Nella tua libreria",
+ "why": "Perché questo?",
+ "wishlist": "Wishlist",
+ "notInterested": "Non mi interessa",
+ "parts": {
+ "label": "Come si calcola il punteggio",
+ "a": "Simile agli artisti di partenza",
+ "g": "Generi vicini ai tuoi gusti",
+ "p": "Quello che ascolti",
+ "d": "Non ancora ascoltato",
+ "noGenre": "Nessun dato sui generi"
+ },
"listening": {
"label": "Avvia Discover dai miei ascolti",
"help": "Se è acceso, i nomi degli artisti che ascolti di più vanno a Last.fm, se un admin l'ha acceso, per trovare artisti simili. Se è spento, Discover parte solo dagli artisti che scegli tu.",
diff --git a/web/src/pages/discover/SuggestionCard.test.tsx b/web/src/pages/discover/SuggestionCard.test.tsx
new file mode 100644
index 0000000..314d8b2
--- /dev/null
+++ b/web/src/pages/discover/SuggestionCard.test.tsx
@@ -0,0 +1,110 @@
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { render, screen, within } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { MemoryRouter } from 'react-router-dom'
+import { beforeEach, expect, test, vi } from 'vitest'
+import type { Suggestion } from '@/api/discover'
+import { sessionStore } from '@/auth/session'
+import { initI18n } from '@/i18n'
+import { apiError, mockFetch } from '@/test/mockFetch'
+import SuggestionCard from './SuggestionCard'
+
+const none = () => new Response(null, { status: 204 })
+
+function make(over: Partial = {}): Suggestion {
+ return {
+ artist: { id: 7, name: 'Portishead' },
+ in_library: false,
+ wishlisted: false,
+ score: 0.824,
+ components: { a: 0.6, g: 0.45, p: 0.5, d: 1 },
+ because: [
+ { artist: { id: 1, name: 'Björk' }, match: 0.9 },
+ { artist: { id: 2, name: 'Massive Attack' }, match: 0.7 },
+ ],
+ ...over,
+ }
+}
+
+function renderCard(suggestion: Suggestion) {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
+ return render(
+
+
+
+
+ ,
+ )
+}
+
+beforeEach(async () => {
+ vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
+ await initI18n()
+ sessionStore.setState({ status: 'authenticated', user: { id: 1, username: 'tom', is_admin: false } })
+})
+
+test('it names the artist with a link, the score in percent, and what it comes from', () => {
+ renderCard(make())
+ expect(screen.getByRole('link', { name: 'Portishead' })).toHaveAttribute('href', '/artists/7')
+ expect(screen.getByText('82% match')).toBeInTheDocument()
+ expect(screen.getByText('Because of Björk, Massive Attack')).toBeInTheDocument()
+})
+
+test('an artist with no reason to give says nothing about one', () => {
+ renderCard(make({ because: [] }))
+ expect(screen.queryByText(/Because of/)).not.toBeInTheDocument()
+})
+
+test('an artist you already have says so', () => {
+ renderCard(make({ in_library: true }))
+ expect(screen.getByText('In your library')).toBeInTheDocument()
+})
+
+test('the score can be explained part by part, and a missing genre is not a zero', async () => {
+ renderCard(make({ components: { a: 0.6, g: null, p: 0.5, d: 1 } }))
+ await userEvent.click(screen.getByText('Why this?'))
+ const parts = screen.getByRole('list', { name: 'How the score is made' })
+ expect(within(parts).getByText('Similar to your starting artists').closest('li')).toHaveTextContent('60%')
+ expect(within(parts).getByText('Genres close to your taste').closest('li')).toHaveTextContent('No genre data')
+ expect(within(parts).getByText('Genres close to your taste').closest('li')).not.toHaveTextContent('0%')
+ expect(within(parts).getByText('What you play').closest('li')).toHaveTextContent('50%')
+ expect(within(parts).getByText('Not played yet').closest('li')).toHaveTextContent('100%')
+})
+
+test('a known genre part is shown in percent', async () => {
+ renderCard(make())
+ await userEvent.click(screen.getByText('Why this?'))
+ expect(screen.getByText('Genres close to your taste').closest('li')).toHaveTextContent('45%')
+})
+
+test('adding to the wishlist puts the artist there', async () => {
+ const { calls } = mockFetch({ 'PUT /api/v1/wishlist/7': none })
+ renderCard(make())
+ const button = screen.getByRole('button', { name: 'Wishlist' })
+ expect(button).toHaveAttribute('aria-pressed', 'false')
+ await userEvent.click(button)
+ expect(calls.map((c) => c.key)).toContain('PUT /api/v1/wishlist/7')
+})
+
+test('a wishlisted artist is shown as pressed, and a click takes it off', async () => {
+ const { calls } = mockFetch({ 'DELETE /api/v1/wishlist/7': none })
+ renderCard(make({ wishlisted: true }))
+ const button = screen.getByRole('button', { name: 'Wishlist' })
+ expect(button).toHaveAttribute('aria-pressed', 'true')
+ await userEvent.click(button)
+ expect(calls.map((c) => c.key)).toContain('DELETE /api/v1/wishlist/7')
+})
+
+test('"Not interested" dismisses the artist', async () => {
+ const { calls } = mockFetch({ 'POST /api/v1/discover/7/dismiss': none })
+ renderCard(make())
+ await userEvent.click(screen.getByRole('button', { name: 'Not interested' }))
+ expect(calls.map((c) => c.key)).toContain('POST /api/v1/discover/7/dismiss')
+})
+
+test('an action that fails says so in words', async () => {
+ mockFetch({ 'PUT /api/v1/wishlist/7': () => apiError(404, 'artist_not_found') })
+ renderCard(make())
+ await userEvent.click(screen.getByRole('button', { name: 'Wishlist' }))
+ expect(await screen.findByRole('alert')).toBeInTheDocument()
+})
diff --git a/web/src/pages/discover/SuggestionCard.tsx b/web/src/pages/discover/SuggestionCard.tsx
new file mode 100644
index 0000000..0e2b893
--- /dev/null
+++ b/web/src/pages/discover/SuggestionCard.tsx
@@ -0,0 +1,77 @@
+import { useTranslation } from 'react-i18next'
+import { Link } from 'react-router-dom'
+import { ApiError } from '@/api/client'
+import { useArtistMarks, type Suggestion } from '@/api/discover'
+import ArtistPhoto from '@/components/ArtistPhoto'
+import { Button } from '@/components/ui/button'
+import { errorMessageKey } from '@/i18n'
+
+const percent = (value: number) => `${Math.round(value * 100)}%`
+
+/** One part of the score, in words, with its share. A part that could not be worked out says so, not "0%". */
+function Part({ label, value, missing }: { label: string; value: number | null; missing: string }) {
+ return (
+
+ )
+}
+
+/** An artist Discover suggests, with how sure it is and why, and what you can do about it. */
+export default function SuggestionCard({ suggestion }: { suggestion: Suggestion }) {
+ const { t } = useTranslation()
+ const marks = useArtistMarks()
+ const { artist, components: parts } = suggestion
+ const failure = marks.addToWishlist.error ?? marks.removeFromWishlist.error ?? marks.dismiss.error
+
+ return (
+
+ )
+}
From 88d3df9f6164d3c26286a54943c9159bc3461b9b Mon Sep 17 00:00:00 2001
From: tgiachi
Date: Thu, 12 Nov 2026 14:11:27 +0100
Subject: [PATCH 07/10] feat(web): the Discover page with its three tabs, a
sidebar link and a route
The tab is kept in the address (?tab=) and moves with the arrow keys; only the open tab asks the server for its list. README now describes Discover in the web app.
---
README.md | 6 +-
web/src/components/layout/Shell.test.tsx | 3 +-
web/src/components/layout/Sidebar.tsx | 1 +
web/src/i18n/locales/en.json | 7 ++
web/src/i18n/locales/it.json | 7 ++
web/src/pages/DiscoverPage.test.tsx | 91 ++++++++++++++++++++++++
web/src/pages/DiscoverPage.tsx | 73 +++++++++++++++++++
web/src/router.tsx | 2 +
8 files changed, 186 insertions(+), 4 deletions(-)
create mode 100644 web/src/pages/DiscoverPage.test.tsx
create mode 100644 web/src/pages/DiscoverPage.tsx
diff --git a/README.md b/README.md
index 1c45b13..a91b558 100644
--- a/README.md
+++ b/README.md
@@ -27,7 +27,7 @@ It is a single executable, one database (SQLite by default, PostgreSQL if you pr
## What is not there yet
-Radio queues, OpenSubsonic compatibility, transcoding, and the ListenBrainz integration. The web client exists (see [Web app](#web-app)) but `sondad` does not serve it yet, and it has no Discover or admin screens yet.
+Radio queues, OpenSubsonic compatibility, transcoding, and the ListenBrainz integration. The web client exists (see [Web app](#web-app)) but `sondad` does not serve it yet, and it has no admin screens or Lidarr button yet.
## Requirements
@@ -328,9 +328,9 @@ npm install
SONDA_URL=http://127.0.0.1:8080 npm run dev # open http://localhost:5173, /api is proxied to Sonda
```
-What it does today: sign in (and create the first account of a new server), browse artists, albums and songs, search, and play with a queue, shuffle, repeat, media keys and a full-screen player. Artist pages show the Wikipedia text, similar artists and tags when those providers are on, each with its credit, and the photo credit next to the photo. It reports one listen per play. There are six themes (Sonda, Tokyo Night, Gruvbox dark, Gruvbox light, Dracula and Neon) and two languages (English and Italian), both chosen in Settings.
+What it does today: sign in (and create the first account of a new server), browse artists, albums and songs, search, and play with a queue, shuffle, repeat, media keys and a full-screen player. Artist pages show the Wikipedia text, similar artists and tags when those providers are on, each with its credit, and the photo credit next to the photo. It reports one listen per play. Discover suggests artists from the ones you pick, or from your listening only after you allow it (a dialog says that their names go to Last.fm), explains each score, and keeps your wishlist and the artists you are not interested in. There are six themes (Sonda, Tokyo Night, Gruvbox dark, Gruvbox light, Dracula and Neon) and two languages (English and Italian), both chosen in Settings.
-More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). Discover, the admin screens and serving the app from the binary come later.
+More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). The Lidarr button, the admin screens and serving the app from the binary come later.
## Development
diff --git a/web/src/components/layout/Shell.test.tsx b/web/src/components/layout/Shell.test.tsx
index c7df56a..49d0547 100644
--- a/web/src/components/layout/Shell.test.tsx
+++ b/web/src/components/layout/Shell.test.tsx
@@ -28,7 +28,7 @@ test('at /artists the Artists link is the current page and the others are not',
renderAt('/artists')
const nav = within(mainNav())
expect(nav.getByRole('link', { name: 'Artists' })).toHaveAttribute('aria-current', 'page')
- for (const name of ['Home', 'Search', 'Albums', 'Songs', 'Settings']) {
+ for (const name of ['Home', 'Search', 'Discover', 'Albums', 'Songs', 'Settings']) {
expect(nav.getByRole('link', { name })).not.toHaveAttribute('aria-current')
}
})
@@ -59,6 +59,7 @@ test.each([
['/artists', 'Artists'],
['/albums', 'Albums'],
['/songs', 'Songs'],
+ ['/discover', 'Discover'],
['/settings', 'Settings'],
])('the route %s opens a page headed %s', (path, heading) => {
renderAt(path)
diff --git a/web/src/components/layout/Sidebar.tsx b/web/src/components/layout/Sidebar.tsx
index 3f099b7..3b1c16f 100644
--- a/web/src/components/layout/Sidebar.tsx
+++ b/web/src/components/layout/Sidebar.tsx
@@ -5,6 +5,7 @@ import { cn } from '@/lib/utils'
const LINKS = [
{ to: '/', key: 'nav.home', end: true },
{ to: '/search', key: 'nav.search', end: false },
+ { to: '/discover', key: 'nav.discover', end: false },
{ to: '/artists', key: 'nav.artists', end: false },
{ to: '/albums', key: 'nav.albums', end: false },
{ to: '/songs', key: 'nav.songs', end: false },
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index 7a884b2..06b4462 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -7,6 +7,7 @@
"main": "Main",
"home": "Home",
"search": "Search",
+ "discover": "Discover",
"artists": "Artists",
"albums": "Albums",
"songs": "Songs",
@@ -60,6 +61,12 @@
},
"discover": {
"title": "Discover",
+ "tabs": {
+ "label": "Discover sections",
+ "suggestions": "Suggestions",
+ "wishlist": "Wishlist",
+ "dismissed": "Not interested"
+ },
"score": "{{percent}}% match",
"because": "Because of {{names}}",
"inLibrary": "In your library",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index 890e280..f1c015b 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -7,6 +7,7 @@
"main": "Principale",
"home": "Home",
"search": "Cerca",
+ "discover": "Discover",
"artists": "Artisti",
"albums": "Album",
"songs": "Brani",
@@ -60,6 +61,12 @@
},
"discover": {
"title": "Discover",
+ "tabs": {
+ "label": "Sezioni di Discover",
+ "suggestions": "Suggerimenti",
+ "wishlist": "Wishlist",
+ "dismissed": "Non mi interessa"
+ },
"score": "{{percent}}% di affinità",
"because": "Per via di {{names}}",
"inLibrary": "Nella tua libreria",
diff --git a/web/src/pages/DiscoverPage.test.tsx b/web/src/pages/DiscoverPage.test.tsx
new file mode 100644
index 0000000..e2688b9
--- /dev/null
+++ b/web/src/pages/DiscoverPage.test.tsx
@@ -0,0 +1,91 @@
+import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
+import { render, screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom'
+import { beforeEach, expect, test, vi } from 'vitest'
+import { sessionStore } from '@/auth/session'
+import { initI18n } from '@/i18n'
+import { mockFetch } from '@/test/mockFetch'
+import DiscoverPage from './DiscoverPage'
+
+const empty = { items: [], total: 0, limit: 50, offset: 0 }
+
+function routes() {
+ return {
+ 'GET /api/v1/me/settings': () => ({ discover_from_listening: false }),
+ 'GET /api/v1/me/taste': () => ({ artists: [], tags: [] }),
+ 'GET /api/v1/wishlist': () => empty,
+ 'GET /api/v1/discover/dismissed': () => empty,
+ 'GET /api/v1/discover': () => ({ provider_status: 'ok', attribution: '', from_listening: false, seeds: [], items: [] }),
+ }
+}
+
+function Where() {
+ const { pathname, search } = useLocation()
+ return
+}
+
+function renderPage(path = '/discover') {
+ const client = new QueryClient({ defaultOptions: { queries: { retry: false }, mutations: { retry: false } } })
+ return render(
+
+
+
+
+ } />
+
+
+ ,
+ )
+}
+
+const tab = (name: string) => screen.getByRole('tab', { name })
+
+beforeEach(async () => {
+ vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
+ await initI18n()
+ sessionStore.setState({ status: 'authenticated', user: { id: 1, username: 'tom', is_admin: false } })
+})
+
+test('it opens on the suggestions', async () => {
+ mockFetch(routes())
+ renderPage()
+ expect(screen.getByRole('heading', { level: 1, name: 'Discover' })).toBeInTheDocument()
+ expect(tab('Suggestions')).toHaveAttribute('aria-selected', 'true')
+ expect(tab('Wishlist')).toHaveAttribute('aria-selected', 'false')
+ expect(await screen.findByText('Pick an artist to start from, or let Discover start from your listening.')).toBeInTheDocument()
+})
+
+test('the address names the tab, and only that tab asks the server for its list', async () => {
+ const { calls } = mockFetch(routes())
+ renderPage('/discover?tab=wishlist')
+ expect(tab('Wishlist')).toHaveAttribute('aria-selected', 'true')
+ expect(await screen.findByText('Nothing on your wishlist yet. Add artists from the suggestions.')).toBeInTheDocument()
+ expect(calls.map((c) => c.key)).not.toContain('GET /api/v1/discover')
+ expect(calls.map((c) => c.key)).not.toContain('GET /api/v1/discover/dismissed')
+})
+
+test('choosing a tab changes the address', async () => {
+ mockFetch(routes())
+ renderPage()
+ await userEvent.click(tab('Not interested'))
+ expect(screen.getByTestId('where')).toHaveTextContent('/discover?tab=dismissed')
+ expect(await screen.findByText('You have not dismissed any artist.')).toBeInTheDocument()
+})
+
+test('a tab that does not exist falls back to the suggestions', () => {
+ mockFetch(routes())
+ renderPage('/discover?tab=bogus')
+ expect(tab('Suggestions')).toHaveAttribute('aria-selected', 'true')
+})
+
+test('the arrow keys move between the tabs', async () => {
+ mockFetch(routes())
+ renderPage()
+ tab('Suggestions').focus()
+ await userEvent.keyboard('{ArrowRight}')
+ expect(tab('Wishlist')).toHaveAttribute('aria-selected', 'true')
+ expect(tab('Wishlist')).toHaveFocus()
+ await userEvent.keyboard('{ArrowLeft}{ArrowLeft}')
+ expect(tab('Not interested')).toHaveAttribute('aria-selected', 'true')
+})
diff --git a/web/src/pages/DiscoverPage.tsx b/web/src/pages/DiscoverPage.tsx
new file mode 100644
index 0000000..38024ad
--- /dev/null
+++ b/web/src/pages/DiscoverPage.tsx
@@ -0,0 +1,73 @@
+import { useRef, type KeyboardEvent } from 'react'
+import { useTranslation } from 'react-i18next'
+import { useSearchParams } from 'react-router-dom'
+import { cn } from '@/lib/utils'
+import MarkedList from './discover/MarkedList'
+import SuggestionsTab from './discover/SuggestionsTab'
+
+const TABS = [
+ { id: 'suggestions', key: 'discover.tabs.suggestions' },
+ { id: 'wishlist', key: 'discover.tabs.wishlist' },
+ { id: 'dismissed', key: 'discover.tabs.dismissed' },
+] as const
+
+type TabId = (typeof TABS)[number]['id']
+
+function parse(value: string | null): TabId {
+ return TABS.find((tab) => tab.id === value)?.id ?? 'suggestions'
+}
+
+export default function DiscoverPage() {
+ const { t } = useTranslation()
+ const [params, setParams] = useSearchParams()
+ const current = parse(params.get('tab'))
+ const buttons = useRef>({})
+
+ function choose(id: TabId) {
+ setParams(id === 'suggestions' ? {} : { tab: id })
+ }
+
+ function onKeyDown(event: KeyboardEvent) {
+ const step = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0
+ if (step === 0) return
+ event.preventDefault()
+ const at = TABS.findIndex((tab) => tab.id === current)
+ const next = TABS[(at + step + TABS.length) % TABS.length].id
+ choose(next)
+ buttons.current[next]?.focus()
+ }
+
+ return (
+
+
{t('discover.title')}
+
+
+ {TABS.map((tab) => (
+
+ ))}
+
+
+
+ {current === 'suggestions' ? : }
+
+
+ )
+}
diff --git a/web/src/router.tsx b/web/src/router.tsx
index 1771082..2c6c6bd 100644
--- a/web/src/router.tsx
+++ b/web/src/router.tsx
@@ -4,6 +4,7 @@ import AlbumPage from '@/pages/AlbumPage'
import AlbumsPage from '@/pages/AlbumsPage'
import ArtistPage from '@/pages/ArtistPage'
import ArtistsPage from '@/pages/ArtistsPage'
+import DiscoverPage from '@/pages/DiscoverPage'
import HomePage from '@/pages/HomePage'
import NotFoundPage from '@/pages/NotFoundPage'
import SearchPage from '@/pages/SearchPage'
@@ -16,6 +17,7 @@ export const routes: RouteObject[] = [
children: [
{ path: '/', element: },
{ path: '/search', element: },
+ { path: '/discover', element: },
{ path: '/artists', element: },
{ path: '/artists/:id', element: },
{ path: '/albums', element: },
From 0198a6d10b645af3f5906973f84317cd02cd505a Mon Sep 17 00:00:00 2001
From: tgiachi
Date: Thu, 12 Nov 2026 14:12:57 +0100
Subject: [PATCH 08/10] fix(web): say what to do when Discover starts from a
listening that is empty
Found against a real server: with the setting on and nothing played, the answer is empty with no seeds. The page now says to play something or pick an artist, instead of a plain 'no suggestions'.
---
web/src/i18n/locales/en.json | 1 +
web/src/i18n/locales/it.json | 1 +
web/src/pages/discover/SuggestionsTab.test.tsx | 7 +++++++
web/src/pages/discover/SuggestionsTab.tsx | 5 ++++-
4 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json
index 06b4462..bc7c048 100644
--- a/web/src/i18n/locales/en.json
+++ b/web/src/i18n/locales/en.json
@@ -78,6 +78,7 @@
"fromListening": "Started from your listening: {{names}}",
"onlyNew": "Only artists I do not have",
"none": "No suggestions yet.",
+ "nothingPlayed": "You have not played anything to start from yet. Play something, or pick an artist above.",
"partial": "Last.fm could not be reached for some artists, so this list may be shorter.",
"busy": "Discover is busy with another request. Try again in a moment.",
"retryIn": "Try again in {{seconds}} s",
diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json
index f1c015b..7994d96 100644
--- a/web/src/i18n/locales/it.json
+++ b/web/src/i18n/locales/it.json
@@ -78,6 +78,7 @@
"fromListening": "Partito dai tuoi ascolti: {{names}}",
"onlyNew": "Solo artisti che non ho",
"none": "Ancora nessun suggerimento.",
+ "nothingPlayed": "Non hai ancora ascoltato niente da cui partire. Ascolta qualcosa, oppure scegli un artista qui sopra.",
"partial": "Last.fm non era raggiungibile per alcuni artisti, quindi la lista può essere più corta.",
"busy": "Discover è occupato con un'altra richiesta. Riprova tra poco.",
"retryIn": "Riprova tra {{seconds}} s",
diff --git a/web/src/pages/discover/SuggestionsTab.test.tsx b/web/src/pages/discover/SuggestionsTab.test.tsx
index 4cd85fc..2a15aa9 100644
--- a/web/src/pages/discover/SuggestionsTab.test.tsx
+++ b/web/src/pages/discover/SuggestionsTab.test.tsx
@@ -144,6 +144,13 @@ test('when Last.fm failed for some artists the rest is shown with a warning', as
expect(screen.getByText('Last.fm could not be reached for some artists, so this list may be shorter.')).toBeInTheDocument()
})
+test('starting from a listening that is empty says to play something, not just "nothing"', async () => {
+ mockFetch(routes(true, { 'GET /api/v1/discover': () => answer({ from_listening: true, seeds: [], items: [] }) }))
+ renderTab()
+ expect(await screen.findByText('You have not played anything to start from yet. Play something, or pick an artist above.')).toBeInTheDocument()
+ expect(screen.queryByText('No suggestions yet.')).not.toBeInTheDocument()
+})
+
test('an empty answer says there is nothing yet', async () => {
mockFetch(routes(true, { 'GET /api/v1/discover': () => answer({ items: [] }) }))
renderTab()
diff --git a/web/src/pages/discover/SuggestionsTab.tsx b/web/src/pages/discover/SuggestionsTab.tsx
index f7e75a1..1da125e 100644
--- a/web/src/pages/discover/SuggestionsTab.tsx
+++ b/web/src/pages/discover/SuggestionsTab.tsx
@@ -101,7 +101,10 @@ export default function SuggestionsTab() {
)}
{data.items.length === 0 ? (
- {t('discover.none')}
+
+ {/* Listening was the only start and it is empty: say what to do, not just "nothing". */}
+ {data.from_listening && data.seeds.length === 0 && seeds.length === 0 ? t('discover.nothingPlayed') : t('discover.none')}
+
) : (
{data.items.map((item) => (
From edbe212f463f0c7dab35f44e907c6d631bc6362b Mon Sep 17 00:00:00 2001
From: tgiachi
Date: Thu, 12 Nov 2026 14:15:51 +0100
Subject: [PATCH 09/10] 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.
---
web/src/components/ListeningSwitch.tsx | 4 +--
web/src/pages/discover/SeedPicker.test.tsx | 29 +++++++++++++++++++---
web/src/pages/discover/SeedPicker.tsx | 14 ++++++++---
web/src/pages/discover/SuggestionCard.tsx | 8 +++---
4 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/web/src/components/ListeningSwitch.tsx b/web/src/components/ListeningSwitch.tsx
index 6b37dc4..b493bc7 100644
--- a/web/src/components/ListeningSwitch.tsx
+++ b/web/src/components/ListeningSwitch.tsx
@@ -41,8 +41,8 @@ export default function ListeningSwitch() {
diff --git a/web/src/pages/discover/SeedPicker.test.tsx b/web/src/pages/discover/SeedPicker.test.tsx
index 8f3c7f7..ffa031e 100644
--- a/web/src/pages/discover/SeedPicker.test.tsx
+++ b/web/src/pages/discover/SeedPicker.test.tsx
@@ -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 () => {
diff --git a/web/src/pages/discover/SeedPicker.tsx b/web/src/pages/discover/SeedPicker.tsx
index da7041b..239ffc3 100644
--- a/web/src/pages/discover/SeedPicker.tsx
+++ b/web/src/pages/discover/SeedPicker.tsx
@@ -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 (
)}
From 44dbc727aa2a205495e0ab8b976ba86e5e852e79 Mon Sep 17 00:00:00 2001
From: tgiachi
Date: Thu, 12 Nov 2026 14:17:05 +0100
Subject: [PATCH 10/10] fix(web): no photo lookups for artists you do not have,
and stale suggestions after changes
A suggestion for an artist outside the library no longer asks for its photo, since that makes the server look the name up at the providers for every card. Changing a wish or a dismissal marks the kept suggestions old without asking Discover at once. Visible focus on the switch, the tabs and the chip buttons.
---
web/src/api/discover.test.tsx | 13 ++++++++++++
web/src/api/discover.ts | 7 ++++++-
web/src/components/ArtistPhoto.tsx | 20 ++++++++++++++++---
web/src/components/ListeningSwitch.tsx | 2 +-
web/src/pages/DiscoverPage.tsx | 2 +-
web/src/pages/discover/SeedPicker.tsx | 2 +-
.../pages/discover/SuggestionCard.test.tsx | 11 ++++++++++
web/src/pages/discover/SuggestionCard.tsx | 2 +-
8 files changed, 51 insertions(+), 8 deletions(-)
diff --git a/web/src/api/discover.test.tsx b/web/src/api/discover.test.tsx
index eccfd0f..d7ae582 100644
--- a/web/src/api/discover.test.tsx
+++ b/web/src/api/discover.test.tsx
@@ -156,3 +156,16 @@ test('being interested again lifts the dismissal', async () => {
await act(() => result.current.undismiss.mutateAsync(7))
expect(calls.map((c) => c.key)).toEqual(['DELETE /api/v1/discover/7/dismiss'])
})
+
+test('being interested again makes the kept suggestions old, without asking Discover at once', async () => {
+ const { calls } = mockFetch({ 'DELETE /api/v1/discover/7/dismiss': () => new Response(null, { status: 204 }) })
+ const { client, wrapper } = setup()
+ const key = ['discover', { seeds: [1], inLibrary: undefined }]
+ client.setQueryData(key, discover([suggestion(8)]))
+ const { result } = renderHook(() => useArtistMarks(), { wrapper })
+ await act(() => result.current.undismiss.mutateAsync(7))
+ // The artist is missing from what is kept, so the next visit must read it again; nobody is looking now, and
+ // the call is heavy, so nothing is asked yet.
+ expect(client.getQueryState(key)?.isInvalidated).toBe(true)
+ expect(calls.map((c) => c.key)).not.toContain('GET /api/v1/discover')
+})
diff --git a/web/src/api/discover.ts b/web/src/api/discover.ts
index d72375f..b54041d 100644
--- a/web/src/api/discover.ts
+++ b/web/src/api/discover.ts
@@ -94,7 +94,12 @@ export function useArtistMarks() {
onError: (_e: unknown, _id: number, context?: { before: Snapshot }) => {
for (const [key, data] of context?.before ?? []) client.setQueryData(key, data)
},
- onSettled: () => refreshLists(client),
+ onSettled: () => {
+ // What is kept may now lack an artist (interested again) or be wrong if the call failed: mark it old so the
+ // next visit reads it again. Nothing is asked now: Discover is heavy and the screen already shows the change.
+ void client.invalidateQueries({ queryKey: [DISCOVER], refetchType: 'none' })
+ return refreshLists(client)
+ },
}
}
diff --git a/web/src/components/ArtistPhoto.tsx b/web/src/components/ArtistPhoto.tsx
index 3aa2639..1850d4f 100644
--- a/web/src/components/ArtistPhoto.tsx
+++ b/web/src/components/ArtistPhoto.tsx
@@ -6,8 +6,22 @@ function initial(name: string): string {
return Array.from(name.trim())[0]?.toUpperCase() ?? '?'
}
-/** A round photo of an artist, or the first letter of the name when there is no free picture. */
-export default function ArtistPhoto({ artistId, name, size }: { artistId: number; name: string; size: number }) {
+/**
+ * A round photo of an artist, or the first letter of the name when there is no free picture. With `photo`
+ * false it never asks for the picture: asking makes the server look the artist up at the providers, which a
+ * list of names nobody chose should not do.
+ */
+export default function ArtistPhoto({
+ artistId,
+ name,
+ size,
+ photo = true,
+}: {
+ artistId: number
+ name: string
+ size: number
+ photo?: boolean
+}) {
useAccessToken() // the URL carries the token, so it has to follow a renewal
const src = mediaUrl(`/artists/${artistId}/image`)
const [failed, setFailed] = useState(null)
@@ -17,7 +31,7 @@ export default function ArtistPhoto({ artistId, name, size }: { artistId: number
style={{ width: size, height: size }}
className="relative flex shrink-0 items-center justify-center overflow-hidden rounded-md bg-primary text-primary-foreground"
>
- {failed !== src ? (
+ {photo && failed !== src ? (
(on ? change(false) : setAsking(true))}
className={cn(
- 'relative h-7 w-12 shrink-0 rounded-md border border-input transition-colors disabled:opacity-50',
+ 'relative h-7 w-12 shrink-0 rounded-md border border-input transition-colors focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:opacity-50',
on ? 'bg-primary' : 'bg-secondary',
)}
>
diff --git a/web/src/pages/DiscoverPage.tsx b/web/src/pages/DiscoverPage.tsx
index 38024ad..8c256bc 100644
--- a/web/src/pages/DiscoverPage.tsx
+++ b/web/src/pages/DiscoverPage.tsx
@@ -56,7 +56,7 @@ export default function DiscoverPage() {
tabIndex={current === tab.id ? 0 : -1}
onClick={() => choose(tab.id)}
className={cn(
- 'min-h-11 rounded-lg px-4 font-semibold',
+ 'min-h-11 rounded-lg px-4 font-semibold focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',
current === tab.id ? 'bg-secondary text-foreground' : 'text-muted-foreground hover:text-foreground',
)}
>
diff --git a/web/src/pages/discover/SeedPicker.tsx b/web/src/pages/discover/SeedPicker.tsx
index 239ffc3..0362b12 100644
--- a/web/src/pages/discover/SeedPicker.tsx
+++ b/web/src/pages/discover/SeedPicker.tsx
@@ -62,7 +62,7 @@ export default function SeedPicker({
type="button"
aria-label={t('discover.seeds.remove', { name: seed.name })}
onClick={() => onRemove(seed.id)}
- className="flex size-7 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground"
+ className="flex size-7 items-center justify-center rounded-sm text-muted-foreground hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring"
>
×
diff --git a/web/src/pages/discover/SuggestionCard.test.tsx b/web/src/pages/discover/SuggestionCard.test.tsx
index 314d8b2..45b67af 100644
--- a/web/src/pages/discover/SuggestionCard.test.tsx
+++ b/web/src/pages/discover/SuggestionCard.test.tsx
@@ -50,6 +50,17 @@ test('it names the artist with a link, the score in percent, and what it comes f
expect(screen.getByText('Because of Björk, Massive Attack')).toBeInTheDocument()
})
+test('an artist you do not have gets no photo request: looking at a list must not ask a provider about each name', () => {
+ renderCard(make({ in_library: false }))
+ expect(screen.queryByRole('img')).not.toBeInTheDocument()
+ expect(screen.getByText('P', { selector: '[data-placeholder]' })).toBeInTheDocument()
+})
+
+test('an artist you have shows its photo', () => {
+ renderCard(make({ in_library: true }))
+ expect(screen.getByRole('img', { name: 'Portishead' })).toBeInTheDocument()
+})
+
test('an artist with no reason to give says nothing about one', () => {
renderCard(make({ because: [] }))
expect(screen.queryByText(/Because of/)).not.toBeInTheDocument()
diff --git a/web/src/pages/discover/SuggestionCard.tsx b/web/src/pages/discover/SuggestionCard.tsx
index 3568645..b550fba 100644
--- a/web/src/pages/discover/SuggestionCard.tsx
+++ b/web/src/pages/discover/SuggestionCard.tsx
@@ -28,7 +28,7 @@ export default function SuggestionCard({ suggestion }: { suggestion: Suggestion
return (