feat(web): a Show photo button on the cards of Discover
A suggested artist you do not have shows a letter, because a photo is a lookup at the providers. The card now has a button that asks for the photo of that one artist when it is pressed, says what it sends, and says so when there is no free photo. Closes #132
This commit is contained in:
parent
cded6f063e
commit
3ade5e80d5
6 changed files with 63 additions and 4 deletions
|
|
@ -352,7 +352,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, shown as cards with a collage of their covers (as the mixes and the smart playlists have): 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, with a collage of the covers of its albums (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. Where a playlist is renamed, and where a smart playlist is edited, a Suggest a name button asks for a name. Smart playlists have their own page too, which begins with the ones Sonda makes for you (ready to play, to keep as a playlist, or to make your own with a click), and then yours: make one with an editor of the rules (genres, format and bitrate, when it was added, your listening and taste, the length, the order and the limit) and a live preview of the songs it gives, play it, shuffle it again (for the random order), keep what you see as a playlist, edit it or delete it; rules by artist and album are in the API only, and an edit keeps them. 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. The web app is a PWA: it has a manifest and a service worker, so a browser can install it (Settings has an Install button where the browser lets a page ask) and it opens at once from its own icon, and shows its own page when the server cannot be reached. The worker keeps only the files of the app (the page, its scripts and styles, the manifest and the icons) and never anything from `/api/`: the catalog, the covers, the songs and what a person did are private and are not kept. A new version waits until you press Reload, so nothing changes under a song. It needs https, or localhost. The menu on the left folds to a narrow bar with the icons of the pages (a button in it, remembered in the browser; on a phone it stays a row of links). 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, shown as cards with a collage of their covers (as the mixes and the smart playlists have): 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, with a collage of the covers of its albums (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. Where a playlist is renamed, and where a smart playlist is edited, a Suggest a name button asks for a name. Smart playlists have their own page too, which begins with the ones Sonda makes for you (ready to play, to keep as a playlist, or to make your own with a click), and then yours: make one with an editor of the rules (genres, format and bitrate, when it was added, your listening and taste, the length, the order and the limit) and a live preview of the songs it gives, play it, shuffle it again (for the random order), keep what you see as a playlist, edit it or delete it; rules by artist and album are in the API only, and an edit keeps them. 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. A suggested artist you do not have shows a letter, not a photo, because a photo is a lookup at the providers: a "Show photo" button on the card asks for that one artist when you press it (the card says it goes to Wikimedia Commons by MusicBrainz id, and says so when there is no free photo). 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. The web app is a PWA: it has a manifest and a service worker, so a browser can install it (Settings has an Install button where the browser lets a page ask) and it opens at once from its own icon, and shows its own page when the server cannot be reached. The worker keeps only the files of the app (the page, its scripts and styles, the manifest and the icons) and never anything from `/api/`: the catalog, the covers, the songs and what a person did are private and are not kept. A new version waits until you press Reload, so nothing changes under a song. It needs https, or localhost. The menu on the left folds to a narrow bar with the icons of the pages (a button in it, remembered in the browser; on a phone it stays a row of links). 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`.
|
||||
|
||||
|
|
|
|||
|
|
@ -16,11 +16,14 @@ export default function ArtistPhoto({
|
|||
name,
|
||||
size,
|
||||
photo = true,
|
||||
onMissing,
|
||||
}: {
|
||||
artistId: number
|
||||
name: string
|
||||
size: number
|
||||
photo?: boolean
|
||||
/** Called when the picture could not be had (there is none, or the provider is off). */
|
||||
onMissing?: () => void
|
||||
}) {
|
||||
useAccessToken() // the URL carries the token, so it has to follow a renewal
|
||||
const src = mediaUrl(`/artists/${artistId}/image`)
|
||||
|
|
@ -37,7 +40,10 @@ export default function ArtistPhoto({
|
|||
alt={name}
|
||||
loading="lazy"
|
||||
className="size-full object-cover"
|
||||
onError={() => setFailed(src)}
|
||||
onError={() => {
|
||||
setFailed(src)
|
||||
onMissing?.()
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<span data-placeholder aria-hidden="true" className="font-extrabold" style={{ fontSize: size * 0.4 }}>
|
||||
|
|
|
|||
|
|
@ -407,6 +407,12 @@
|
|||
"inLibrary": "In your library",
|
||||
"why": "Why this?",
|
||||
"wishlist": "Wishlist",
|
||||
"photo": {
|
||||
"show": "Show photo of {{name}}",
|
||||
"button": "Show photo",
|
||||
"hint": "Asks Wikimedia Commons for a free photo of this artist, using its MusicBrainz id. Needs the Commons and MusicBrainz providers to be on.",
|
||||
"none": "No free photo found."
|
||||
},
|
||||
"notInterested": "Not interested",
|
||||
"invite": "Pick an artist to start from, or let Discover start from your listening.",
|
||||
"waiting": "Asking Last.fm can take several seconds.",
|
||||
|
|
|
|||
|
|
@ -407,6 +407,12 @@
|
|||
"inLibrary": "Nella tua libreria",
|
||||
"why": "Perché questo?",
|
||||
"wishlist": "Wishlist",
|
||||
"photo": {
|
||||
"show": "Mostra la foto di {{name}}",
|
||||
"button": "Mostra foto",
|
||||
"hint": "Chiede a Wikimedia Commons una foto libera di questo artista, usando il suo id MusicBrainz. Servono i provider Commons e MusicBrainz accesi.",
|
||||
"none": "Nessuna foto libera trovata."
|
||||
},
|
||||
"notInterested": "Non mi interessa",
|
||||
"invite": "Scegli un artista da cui partire, oppure lascia che Discover parta dai tuoi ascolti.",
|
||||
"waiting": "Interrogare Last.fm può richiedere diversi secondi.",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
||||
import { render, screen, within } from '@testing-library/react'
|
||||
import { fireEvent, 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'
|
||||
|
|
@ -56,6 +56,29 @@ test('an artist you do not have gets no photo request: looking at a list must no
|
|||
expect(screen.getByText('P', { selector: '[data-placeholder]' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('a button asks for the photo of one artist you do not have, and the photo comes only after it is pressed', async () => {
|
||||
renderCard(make({ in_library: false }))
|
||||
const button = screen.getByRole('button', { name: 'Show photo of Portishead' })
|
||||
expect(button).toHaveAttribute('title', expect.stringContaining('Wikimedia Commons'))
|
||||
expect(screen.queryByRole('img')).not.toBeInTheDocument()
|
||||
await userEvent.click(button)
|
||||
expect(screen.getByRole('img', { name: 'Portishead' })).toHaveAttribute('src', expect.stringContaining('/artists/7/image'))
|
||||
expect(screen.queryByRole('button', { name: /Show photo/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('when the artist has no free photo the card says so and keeps the letter', async () => {
|
||||
renderCard(make({ in_library: false }))
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Show photo of Portishead' }))
|
||||
fireEvent.error(screen.getByRole('img', { name: 'Portishead' }))
|
||||
expect(screen.getByText('No free photo found.')).toBeInTheDocument()
|
||||
expect(screen.getByText('P', { selector: '[data-placeholder]' })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('an artist you have has no such button: its photo is already shown', () => {
|
||||
renderCard(make({ in_library: true }))
|
||||
expect(screen.queryByRole('button', { name: /Show photo/ })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
test('an artist you have shows its photo', () => {
|
||||
renderCard(make({ in_library: true }))
|
||||
expect(screen.getByRole('img', { name: 'Portishead' })).toBeInTheDocument()
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { ApiError } from '@/api/client'
|
||||
|
|
@ -23,13 +24,18 @@ function Part({ label, value, missing }: { label: string; value: number | null;
|
|||
export default function SuggestionCard({ suggestion }: { suggestion: Suggestion }) {
|
||||
const { t } = useTranslation()
|
||||
const marks = useArtistMarks()
|
||||
// A photo of an artist you do not have is looked up only when asked, one artist at a time.
|
||||
const [asked, setAsked] = useState(false)
|
||||
const [noPhoto, setNoPhoto] = useState(false)
|
||||
const { artist, components: parts } = suggestion
|
||||
const failure = marks.addToWishlist.error ?? marks.removeFromWishlist.error ?? marks.dismiss.error
|
||||
|
||||
return (
|
||||
<li className="flex flex-col gap-3 rounded-lg bg-card p-4 text-card-foreground">
|
||||
<div className="flex flex-wrap items-center gap-4">
|
||||
<ArtistPhoto artistId={artist.id} name={artist.name} size={56} photo={suggestion.in_library} />
|
||||
<ArtistPhoto artistId={artist.id} name={artist.name} size={56} photo={suggestion.in_library || asked}
|
||||
onMissing={() => setNoPhoto(true)}
|
||||
/>
|
||||
<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}
|
||||
|
|
@ -38,6 +44,18 @@ export default function SuggestionCard({ suggestion }: { suggestion: Suggestion
|
|||
<span>{t('discover.score', { percent: Math.round(suggestion.score * 100) })}</span>
|
||||
{suggestion.in_library && <span>{t('discover.inLibrary')}</span>}
|
||||
</div>
|
||||
{!suggestion.in_library && !asked && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
className="-ml-2 self-start px-2 text-sm text-primary"
|
||||
aria-label={t('discover.photo.show', { name: artist.name })}
|
||||
title={t('discover.photo.hint')}
|
||||
onClick={() => setAsked(true)}
|
||||
>
|
||||
{t('discover.photo.button')}
|
||||
</Button>
|
||||
)}
|
||||
{noPhoto && <span className="text-sm text-muted-foreground">{t('discover.photo.none')}</span>}
|
||||
{suggestion.because.length > 0 && (
|
||||
<p className="text-sm break-words text-muted-foreground">
|
||||
{t('discover.because', { names: suggestion.because.map((b) => b.artist.name).join(', ') })}
|
||||
|
|
|
|||
Loading…
Reference in a new issue