sonda/web/src/api/providers.ts
tgiachi e2899c6647 feat(web): artists, albums and songs pages with provider data and attribution
- lists of artists, albums and songs, loaded 50 at a time, with the search text taken from the address
- album page and artist page; a click on a song plays the list from there
- artist page shows a Wikipedia text, similar artists and tags with their credits, and the photo credit
- providers that are off, unreachable or without an id give a short explanation, never an error page
- artists a provider named, with nothing to play, still have a page
2026-11-12 11:36:35 +01:00

47 lines
1.5 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { api, ApiError } from './client'
import type { components } from './schema'
export type ArtistDescription = components['schemas']['ArtistDescription']
export type SimilarArtists = components['schemas']['SimilarArtists']
export type ArtistTags = components['schemas']['ArtistTags']
export type PictureCredit = components['schemas']['PictureCredit']
export function useArtistDescription(id: number) {
return useQuery({
queryKey: ['artist', id, 'description'],
queryFn: () => api.get<ArtistDescription>(`/artists/${id}/description`),
})
}
export function useSimilarArtists(id: number) {
return useQuery({
queryKey: ['artist', id, 'similar'],
queryFn: () => api.get<SimilarArtists>(`/artists/${id}/similar`),
})
}
export function useArtistTags(id: number) {
return useQuery({
queryKey: ['artist', id, 'tags'],
queryFn: () => api.get<ArtistTags>(`/artists/${id}/tags`),
})
}
/**
* The credit of the artist photo. There is no credit when there is no picture (provider off, no free
* picture, no MusicBrainz id) or the picture provider is down: those answer `null`, not an error.
*/
export function useArtistImageCredit(id: number) {
return useQuery({
queryKey: ['artist', id, 'image-credit'],
queryFn: async () => {
try {
return await api.get<PictureCredit>(`/artists/${id}/image/credit`)
} catch (e) {
if (e instanceof ApiError && (e.status === 404 || e.status === 502)) return null
throw e
}
},
})
}