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.
This commit is contained in:
parent
edbe212f46
commit
44dbc727aa
8 changed files with 51 additions and 8 deletions
|
|
@ -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')
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<string | null>(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 ? (
|
||||
<img
|
||||
src={src}
|
||||
alt={name}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ export default function ListeningSwitch() {
|
|||
disabled={settings.data === undefined || update.isPending}
|
||||
onClick={() => (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',
|
||||
)}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
)}
|
||||
>
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
>
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ 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 flex-wrap items-center gap-4">
|
||||
<ArtistPhoto artistId={artist.id} name={artist.name} size={56} />
|
||||
<ArtistPhoto artistId={artist.id} name={artist.name} size={56} photo={suggestion.in_library} />
|
||||
<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}
|
||||
|
|
|
|||
Loading…
Reference in a new issue