diff --git a/README.md b/README.md index 41489d7..e25b491 100644 --- a/README.md +++ b/README.md @@ -342,7 +342,7 @@ 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, a volume slider with mute (remembered in the browser) 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. Playlists have a page of their own: make one, put a song in it with the button next to any song (or make a new playlist right there), play it, rename it, delete it, move a song up or down and take one out; a song whose files are gone is shown as not available and skipped when the playlist plays. 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. An admin who set up the `lidarr` provider gets a "Request on Lidarr" button on an artist's page and on the Discover cards: it asks first, then sends that one artist to their own Lidarr, which does the downloading (the web app downloads nothing; the page of an artist reads what Lidarr has, the cards ask nothing until you send). An admin also gets an Admin area to add, rename, move and remove libraries and to start a scan (of one library or all, optionally reading every file again) and follow it, and to manage accounts: add one by email, give or take away the admin role, reset a password (which ends that person's sessions) and delete an account. The last admin cannot be changed, and your own account has no buttons there. Providers have a card each that says what the provider is sent: turning one on asks first, the API key is write-only (never shown, and gone from the page once saved), and there are a test of the key, the contact or address, removing what a provider gave, and, for Lidarr, the profiles and root folder to use when an artist is added. The bulk jobs (album covers, artist pictures, artist descriptions) each have a card that says what the job sends and to whom: starting one asks first and says it goes through the whole library, reading everything again is a separate choice, a job whose providers are off cannot be started, and the page follows its progress and can stop it. 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, a volume slider with mute (remembered in the browser) 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. Playlists have a page of their own: make one, put a song in it with the button next to any song (or make a new playlist right there), play it, rename it, delete it, move a song up or down and take one out; a song whose files are gone is shown as not available and skipped when the playlist plays. Mixes have a page too: a card for each mix (the ones from your listening first, then one for each genre), and on a mix its songs, Play, Shuffle again (another set of songs) and Save as playlist, which keeps what you see as a playlist of your own. 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. An admin who set up the `lidarr` provider gets a "Request on Lidarr" button on an artist's page and on the Discover cards: it asks first, then sends that one artist to their own Lidarr, which does the downloading (the web app downloads nothing; the page of an artist reads what Lidarr has, the cards ask nothing until you send). An admin also gets an Admin area to add, rename, move and remove libraries and to start a scan (of one library or all, optionally reading every file again) and follow it, and to manage accounts: add one by email, give or take away the admin role, reset a password (which ends that person's sessions) and delete an account. The last admin cannot be changed, and your own account has no buttons there. Providers have a card each that says what the provider is sent: turning one on asks first, the API key is write-only (never shown, and gone from the page once saved), and there are a test of the key, the contact or address, removing what a provider gave, and, for Lidarr, the profiles and root folder to use when an artist is added. The bulk jobs (album covers, artist pictures, artist descriptions) each have a card that says what the job sends and to whom: starting one asks first and says it goes through the whole library, reading everything again is a separate choice, a job whose providers are off cannot be started, and the page follows its progress and can stop it. 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). `npm run build` writes to `internal/webui/dist` (git-ignored), not to `web/dist`. diff --git a/web/src/api/mixes.ts b/web/src/api/mixes.ts new file mode 100644 index 0000000..74a7588 --- /dev/null +++ b/web/src/api/mixes.ts @@ -0,0 +1,36 @@ +import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query' +import { api } from './client' +import { refresh as refreshPlaylists, type Playlist } from './playlists' +import type { components } from './schema' + +export type Mix = components['schemas']['Mix'] +export type MixWithTracks = components['schemas']['MixWithTracks'] + +/** The id goes in the path, and a genre mix has the genre in it (`genre:hard rock`). */ +const path = (id: string) => `/mixes/${encodeURIComponent(id)}` + +/** The mixes made for me now. */ +export function useMixes() { + return useQuery({ queryKey: ['mixes'], queryFn: () => api.get<{ items: Mix[] }>('/mixes').then((r) => r.items) }) +} + +/** + * A mix with its songs. `variant` 0 is the mix of the day and is not sent; every other number is another set of songs. + * The songs on screen stay until the next ones arrive. + */ +export function useMix(id: string, variant: number) { + return useQuery({ + queryKey: ['mix', id, variant], + queryFn: () => api.get(path(id), variant > 0 ? { variant } : undefined), + placeholderData: keepPreviousData, + }) +} + +/** Keeps the songs of a mix as a playlist of mine. */ +export function useSaveMix() { + const client = useQueryClient() + return useMutation({ + mutationFn: ({ id, ...body }: { id: string; name: string; variant: number }) => api.post(`${path(id)}/playlist`, body), + onSuccess: () => refreshPlaylists(client), + }) +} diff --git a/web/src/api/playlists.ts b/web/src/api/playlists.ts index c3d2a7e..cc959f1 100644 --- a/web/src/api/playlists.ts +++ b/web/src/api/playlists.ts @@ -24,7 +24,7 @@ export function usePlaylistItems(id: number) { } /** Every list and page of playlists is read again: a change moves a playlist to the top and changes its size. */ -function refresh(client: QueryClient) { +export function refresh(client: QueryClient) { return client.invalidateQueries({ predicate: (query) => { const key = query.queryKey[0] diff --git a/web/src/components/layout/Sidebar.tsx b/web/src/components/layout/Sidebar.tsx index 196f5ec..0bbbbe7 100644 --- a/web/src/components/layout/Sidebar.tsx +++ b/web/src/components/layout/Sidebar.tsx @@ -10,6 +10,7 @@ const LINKS = [ { to: '/artists', key: 'nav.artists', end: false, adminOnly: false }, { to: '/albums', key: 'nav.albums', end: false, adminOnly: false }, { to: '/songs', key: 'nav.songs', end: false, adminOnly: false }, + { to: '/mixes', key: 'nav.mixes', end: false, adminOnly: false }, { to: '/playlists', key: 'nav.playlists', end: false, adminOnly: false }, { to: '/admin', key: 'nav.admin', end: false, adminOnly: true }, { to: '/settings', key: 'nav.settings', end: false, adminOnly: false }, diff --git a/web/src/i18n/locales/en.json b/web/src/i18n/locales/en.json index 3407c87..85b3bb9 100644 --- a/web/src/i18n/locales/en.json +++ b/web/src/i18n/locales/en.json @@ -11,6 +11,7 @@ "artists": "Artists", "albums": "Albums", "songs": "Songs", + "mixes": "Mixes", "playlists": "Playlists", "admin": "Admin", "settings": "Settings" @@ -523,7 +524,9 @@ "playlist_not_found": "This playlist does not exist.", "limit_reached": "Limit reached: a user can have 1000 playlists, and a playlist up to 10000 songs.", "track_not_found": "This song no longer exists.", - "invalid_position": "That place no longer exists. Reload the playlist." + "invalid_position": "That place no longer exists. Reload the playlist.", + "mix_not_found": "This mix is not available now.", + "mix_empty": "This mix has no songs to keep." }, "playlists": { "empty": "You have no playlists yet. Make one below, or put a song in a new one with the playlist button next to it.", @@ -555,5 +558,22 @@ "newName": "New playlist name", "createAndAdd": "Create and add", "added": "Added to {{name}}." + }, + "mixes": { + "forYou": "Made for you", + "byGenre": "By genre", + "empty": "No mixes yet. They appear when your library has songs with a genre, or songs you have not heard.", + "kind": { + "favourites": "Your favourites", + "rediscover": "Rediscover", + "unheard": "New to you" + }, + "genreMix": "{{genre}} Mix", + "with": "With {{artists}}", + "notFound": "This mix is not available now. Mixes change with what you listen to.", + "shuffle": "Shuffle again", + "save": "Save as playlist", + "saved": "Saved as “{{name}}”.", + "open": "Open the playlist" } } diff --git a/web/src/i18n/locales/it.json b/web/src/i18n/locales/it.json index e1076ee..cd9c39e 100644 --- a/web/src/i18n/locales/it.json +++ b/web/src/i18n/locales/it.json @@ -11,6 +11,7 @@ "artists": "Artisti", "albums": "Album", "songs": "Brani", + "mixes": "Mix", "playlists": "Playlist", "admin": "Admin", "settings": "Impostazioni" @@ -523,7 +524,9 @@ "playlist_not_found": "Questa playlist non esiste.", "limit_reached": "Limite raggiunto: un utente può avere 1000 playlist e una playlist fino a 10000 brani.", "track_not_found": "Questo brano non esiste più.", - "invalid_position": "Quel posto non esiste più. Ricarica la playlist." + "invalid_position": "Quel posto non esiste più. Ricarica la playlist.", + "mix_not_found": "Questo mix ora non è disponibile.", + "mix_empty": "Questo mix non ha brani da salvare." }, "playlists": { "empty": "Non hai ancora nessuna playlist. Creane una qui sotto, oppure metti un brano in una nuova con il pulsante accanto al brano.", @@ -555,5 +558,22 @@ "newName": "Nome della nuova playlist", "createAndAdd": "Crea e aggiungi", "added": "Aggiunto a {{name}}." + }, + "mixes": { + "forYou": "Fatti per te", + "byGenre": "Per genere", + "empty": "Ancora nessun mix. Compaiono quando la libreria ha brani con un genere, o brani che non hai ancora ascoltato.", + "kind": { + "favourites": "I tuoi preferiti", + "rediscover": "Riscopri", + "unheard": "Nuovi per te" + }, + "genreMix": "Mix {{genre}}", + "with": "Con {{artists}}", + "notFound": "Questo mix ora non è disponibile. I mix cambiano con quello che ascolti.", + "shuffle": "Rimescola", + "save": "Salva come playlist", + "saved": "Salvato come “{{name}}”.", + "open": "Apri la playlist" } } diff --git a/web/src/pages/MixPage.tsx b/web/src/pages/MixPage.tsx new file mode 100644 index 0000000..62da825 --- /dev/null +++ b/web/src/pages/MixPage.tsx @@ -0,0 +1,92 @@ +import { ListPlus, Play, Shuffle } from 'lucide-react' +import { useState } from 'react' +import { useTranslation } from 'react-i18next' +import { Link, useParams } from 'react-router-dom' +import { ApiError } from '@/api/client' +import { useMix, useSaveMix } from '@/api/mixes' +import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status' +import TrackList from '@/components/TrackList' +import { Button } from '@/components/ui/button' +import { errorMessageKey } from '@/i18n' +import { formatTime } from '@/lib/time' +import { usePlayer } from '@/player/store' +import { mixTitle } from './mixTitle' + +export default function MixPage() { + const id = useParams().id ?? '' + // Another mix starts again from the mix of the day. + return +} + +function MixView({ id }: { id: string }) { + const { t } = useTranslation() + const [variant, setVariant] = useState(0) + const query = useMix(id, variant) + const save = useSaveMix() + const playTracks = usePlayer((s) => s.playTracks) + + if (query.isError) { + if (query.error instanceof ApiError && query.error.status === 404) return {t('mixes.notFound')} + return query.refetch()} /> + } + if (!query.data) return + const mix = query.data + const title = mixTitle(t, mix) + const empty = mix.tracks.length === 0 + // The songs shown are still the old ones while the next come: nothing is kept or shuffled then. + const waiting = query.isPlaceholderData + const duration = mix.tracks.reduce((sum, track) => sum + track.duration_ms, 0) + + return ( +
+
+

{title}

+ {mix.artists.length > 0 &&

{t('mixes.with', { artists: mix.artists.join(', ') })}

} +

{t('playlists.meta', { count: mix.tracks.length, duration: formatTime(duration) })}

+
+ + + +
+
+ + {save.isSuccess && ( +

+ {t('mixes.saved', { name: save.data.name })} + + {t('mixes.open')} + +

+ )} + {save.isError && ( +

+ {t(errorMessageKey(save.error instanceof ApiError ? save.error.code : 'unknown'))} +

+ )} + + {!empty && } +
+ ) +} diff --git a/web/src/pages/MixesPage.tsx b/web/src/pages/MixesPage.tsx new file mode 100644 index 0000000..3692cb0 --- /dev/null +++ b/web/src/pages/MixesPage.tsx @@ -0,0 +1,51 @@ +import { useTranslation } from 'react-i18next' +import { Link } from 'react-router-dom' +import { useMixes, type Mix } from '@/api/mixes' +import { CARD_GRID } from '@/components/cards' +import Section from '@/components/Section' +import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status' +import { mixTitle } from './mixTitle' + +function MixCard({ mix }: { mix: Mix }) { + const { t } = useTranslation() + return ( + + {mixTitle(t, mix)} + {mix.artists.join(', ')} + + ) +} + +/** The mixes made for me, the ones from my listening first, then one for each genre. */ +export default function MixesPage() { + const { t } = useTranslation() + const query = useMixes() + const forYou = query.data?.filter((m) => m.kind !== 'genre') ?? [] + const genres = query.data?.filter((m) => m.kind === 'genre') ?? [] + + return ( +
+

{t('nav.mixes')}

+ {query.isError ? ( + query.refetch()} /> + ) : query.isPending ? ( + + ) : query.data.length === 0 ? ( + {t('mixes.empty')} + ) : ( + <> + {forYou.length > 0 && ( +
+
{forYou.map((m) => )}
+
+ )} + {genres.length > 0 && ( +
+
{genres.map((m) => )}
+
+ )} + + )} +
+ ) +} diff --git a/web/src/pages/mixTitle.ts b/web/src/pages/mixTitle.ts new file mode 100644 index 0000000..d51f3a6 --- /dev/null +++ b/web/src/pages/mixTitle.ts @@ -0,0 +1,10 @@ +import type { TFunction } from 'i18next' +import type { Mix } from '@/api/mixes' + +const capitalize = (text: string) => text.replace(/(^|\s)\S/gu, (c) => c.toLocaleUpperCase()) + +/** The name of a mix in the language of the page: the server's title is always English. */ +export function mixTitle(t: TFunction, mix: Pick): string { + if (mix.kind === 'genre' && mix.genre) return t('mixes.genreMix', { genre: capitalize(mix.genre) }) + return t(`mixes.kind.${mix.kind}`) +} diff --git a/web/src/pages/mixes.test.tsx b/web/src/pages/mixes.test.tsx new file mode 100644 index 0000000..e73c0ba --- /dev/null +++ b/web/src/pages/mixes.test.tsx @@ -0,0 +1,220 @@ +import { QueryClient, QueryClientProvider } from '@tanstack/react-query' +import { render, screen, waitFor, within } from '@testing-library/react' +import userEvent from '@testing-library/user-event' +import type { ReactElement } from 'react' +import { MemoryRouter, Route, Routes } from 'react-router-dom' +import { beforeEach, expect, test, vi } from 'vitest' +import { sessionStore } from '@/auth/session' +import { initI18n } from '@/i18n' +import { usePlayer } from '@/player/store' +import { apiError, mockFetch, type MockRoutes } from '@/test/mockFetch' +import MixesPage from './MixesPage' +import MixPage from './MixPage' + +// --- fixtures --------------------------------------------------------------------------------- + +function track(n: number) { + return { + id: n, + title: `Song ${n}`, + duration_ms: 200_000, + track_no: n, + disc_no: 1, + album: { id: 9, title: 'OK Computer' }, + artists: [{ id: 5, name: 'Radiohead' }], + format: 'flac', + } +} + +function mix(id: string, kind: string, genre: string | null, artists: string[] = ['Radiohead']) { + return { id, kind, title: 'a title in English', genre, artists } +} + +function withTracks(id: string, kind: string, genre: string | null, variant: number, tracks: object[]) { + return { ...mix(id, kind, genre), variant, tracks } +} + +const HARD_ROCK = 'genre%3Ahard%20rock' + +function renderPage(element: ReactElement, path: string, routePath: string) { + const client = new QueryClient({ defaultOptions: { queries: { retry: false } } }) + return render( + + + + + THE PLAYLIST PAGE

} /> +
+
+
, + ) +} + +beforeEach(async () => { + vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US') + await initI18n() + sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: false } }) + usePlayer.setState({ queue: [], original: [], index: 0, playing: false, positionMs: 0, shuffle: false, repeat: 'off', seekMs: null, seekId: 0, playId: 0 }) +}) + +// --- the list of mixes -------------------------------------------------------------------------- + +test('the mixes page shows the mixes made from my listening first, then one for each genre', async () => { + mockFetch({ + 'GET /api/v1/mixes': () => ({ + items: [ + mix('favourites', 'favourites', null, ['Radiohead', 'Muse']), + mix('rediscover', 'rediscover', null), + mix('unheard', 'unheard', null), + mix('genre:hard rock', 'genre', 'hard rock', ['Scorpions', 'AC/DC', 'Kiss']), + mix('genre:synthwave', 'genre', 'synthwave', ['The Midnight']), + ], + }), + }) + renderPage(, '/mixes', '/mixes') + + const forYou = await screen.findByRole('region', { name: 'Made for you' }) + const names = within(forYou).getAllByRole('link').map((l) => l.textContent) + expect(names).toEqual([expect.stringContaining('Your favourites'), expect.stringContaining('Rediscover'), expect.stringContaining('New to you')]) + expect(within(forYou).getByRole('link', { name: /Your favourites/ })).toHaveTextContent('Radiohead, Muse') + + const genres = screen.getByRole('region', { name: 'By genre' }) + const rock = within(genres).getByRole('link', { name: /Hard Rock Mix/ }) + expect(rock).toHaveAttribute('href', `/mixes/${HARD_ROCK}`) + expect(rock).toHaveTextContent('Scorpions, AC/DC, Kiss') + expect(within(genres).getByRole('link', { name: /Synthwave Mix/ })).toBeInTheDocument() +}) + +test('a section with no mix is not shown', async () => { + mockFetch({ 'GET /api/v1/mixes': () => ({ items: [mix('unheard', 'unheard', null)] }) }) + renderPage(, '/mixes', '/mixes') + expect(await screen.findByRole('link', { name: /New to you/ })).toBeInTheDocument() + expect(screen.queryByRole('region', { name: 'By genre' })).not.toBeInTheDocument() +}) + +test('with no mix the page says what is needed', async () => { + mockFetch({ 'GET /api/v1/mixes': () => ({ items: [] }) }) + renderPage(, '/mixes', '/mixes') + expect(await screen.findByText(/no mixes yet/i)).toBeInTheDocument() +}) + +test('a failed list says so and can be tried again', async () => { + mockFetch({ 'GET /api/v1/mixes': () => apiError(500, 'unknown') }) + renderPage(, '/mixes', '/mixes') + expect(await screen.findByRole('alert')).toHaveTextContent(/went wrong/i) + expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument() +}) + +// --- one mix ---------------------------------------------------------------------------------- + +const songs = (...ns: number[]) => ns.map(track) + +function oneMix(over: MockRoutes = {}): MockRoutes { + return { + [`GET /api/v1/mixes/${HARD_ROCK}`]: () => withTracks('genre:hard rock', 'genre', 'hard rock', 0, songs(1, 2, 3)), + ...over, + } +} + +const open = () => renderPage(, `/mixes/${HARD_ROCK}`, '/mixes/:id') + +test('a mix shows its name, its artists and its songs in order, and asks for the mix of the day', async () => { + const { calls } = mockFetch(oneMix()) + open() + expect(await screen.findByRole('heading', { level: 1, name: 'Hard Rock Mix' })).toBeInTheDocument() + expect(screen.getByText(/3 songs/)).toBeInTheDocument() + expect(screen.getByRole('button', { name: /Song 1/ })).toBeInTheDocument() + expect(screen.getByRole('button', { name: /Song 3/ })).toBeInTheDocument() + const get = calls.find((c) => c.key.startsWith('GET /api/v1/mixes/'))! + expect(get.url.searchParams.has('variant')).toBe(false) +}) + +test('Play starts the mix from its first song', async () => { + mockFetch(oneMix()) + open() + await userEvent.click(await screen.findByRole('button', { name: 'Play' })) + const { queue, index } = usePlayer.getState() + expect(queue.map((t) => t.id)).toEqual([1, 2, 3]) + expect(index).toBe(0) +}) + +test('Shuffle again asks for the next variant and shows other songs, every time', async () => { + const { calls } = mockFetch( + oneMix({ + [`GET /api/v1/mixes/${HARD_ROCK}`]: ({ url }) => { + const variant = Number(url.searchParams.get('variant') ?? 0) + return withTracks('genre:hard rock', 'genre', 'hard rock', variant, songs(10 * variant + 1, 10 * variant + 2)) + }, + }), + ) + open() + expect(await screen.findByRole('button', { name: /Song 1(?!\d)/ })).toBeInTheDocument() + + await userEvent.click(screen.getByRole('button', { name: 'Shuffle again' })) + expect(await screen.findByRole('button', { name: /Song 11/ })).toBeInTheDocument() + expect(screen.queryByRole('button', { name: /Song 1(?!\d)/ })).not.toBeInTheDocument() + + await userEvent.click(screen.getByRole('button', { name: 'Shuffle again' })) + expect(await screen.findByRole('button', { name: /Song 21/ })).toBeInTheDocument() + + const variants = calls.filter((c) => c.key.startsWith('GET /api/v1/mixes/')).map((c) => c.url.searchParams.get('variant')) + expect(variants).toEqual([null, '1', '2']) +}) + +test('Save as playlist keeps the variant that is shown, names it with the title, and links to it', async () => { + let saved: unknown + const { calls } = mockFetch( + oneMix({ + [`GET /api/v1/mixes/${HARD_ROCK}`]: ({ url }) => + withTracks('genre:hard rock', 'genre', 'hard rock', Number(url.searchParams.get('variant') ?? 0), songs(1, 2)), + [`POST /api/v1/mixes/${HARD_ROCK}/playlist`]: ({ init }) => { + saved = JSON.parse(init.body as string) + return new Response( + JSON.stringify({ id: 42, name: 'Hard Rock Mix', description: '', track_count: 2, duration_ms: 400_000, created_at: '2026-11-12T10:00:00Z', updated_at: '2026-11-12T10:00:00Z' }), + { status: 201, headers: { 'Content-Type': 'application/json' } }, + ) + }, + }), + ) + open() + await userEvent.click(await screen.findByRole('button', { name: 'Shuffle again' })) + await waitFor(() => expect(screen.getByRole('button', { name: 'Save as playlist' })).toBeEnabled()) + await userEvent.click(screen.getByRole('button', { name: 'Save as playlist' })) + + const status = await screen.findByRole('status') + expect(status).toHaveTextContent('Saved as “Hard Rock Mix”') + expect(saved).toEqual({ name: 'Hard Rock Mix', variant: 1 }) + expect(calls.some((c) => c.key === `POST /api/v1/mixes/${HARD_ROCK}/playlist`)).toBe(true) + + await userEvent.click(within(status).getByRole('link', { name: 'Open the playlist' })) + expect(await screen.findByText('THE PLAYLIST PAGE')).toBeInTheDocument() +}) + +test('a mix that cannot be kept says why', async () => { + mockFetch(oneMix({ [`POST /api/v1/mixes/${HARD_ROCK}/playlist`]: () => apiError(422, 'mix_empty') })) + open() + await userEvent.click(await screen.findByRole('button', { name: 'Save as playlist' })) + expect(await screen.findByRole('alert')).toHaveTextContent(/no songs/i) +}) + +test('a mix that does not exist says so', async () => { + mockFetch({ [`GET /api/v1/mixes/${HARD_ROCK}`]: () => apiError(404, 'mix_not_found') }) + open() + expect(await screen.findByText(/not available/i)).toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Play' })).not.toBeInTheDocument() +}) + +test('a mix with no songs cannot be played, shuffled into nothing, or kept', async () => { + mockFetch(oneMix({ [`GET /api/v1/mixes/${HARD_ROCK}`]: () => withTracks('genre:hard rock', 'genre', 'hard rock', 0, []) })) + open() + expect(await screen.findByRole('button', { name: 'Play' })).toBeDisabled() + expect(screen.getByRole('button', { name: 'Save as playlist' })).toBeDisabled() +}) + +test('the mixes made from listening have their own names', async () => { + mockFetch({ + 'GET /api/v1/mixes/rediscover': () => withTracks('rediscover', 'rediscover', null, 0, songs(1)), + }) + renderPage(, '/mixes/rediscover', '/mixes/:id') + expect(await screen.findByRole('heading', { level: 1, name: 'Rediscover' })).toBeInTheDocument() +}) diff --git a/web/src/router.tsx b/web/src/router.tsx index 203ad77..d42c322 100644 --- a/web/src/router.tsx +++ b/web/src/router.tsx @@ -6,6 +6,8 @@ import ArtistPage from '@/pages/ArtistPage' import ArtistsPage from '@/pages/ArtistsPage' import DiscoverPage from '@/pages/DiscoverPage' import HomePage from '@/pages/HomePage' +import MixesPage from '@/pages/MixesPage' +import MixPage from '@/pages/MixPage' import AdminLayout from '@/pages/admin/AdminLayout' import JobsPage from '@/pages/admin/JobsPage' import LibrariesPage from '@/pages/admin/LibrariesPage' @@ -30,6 +32,8 @@ export const routes: RouteObject[] = [ { path: '/albums', element: }, { path: '/albums/:id', element: }, { path: '/songs', element: }, + { path: '/mixes', element: }, + { path: '/mixes/:id', element: }, { path: '/playlists', element: }, { path: '/playlists/:id', element: }, { path: '/settings', element: },