import { unwrap } from '@pipu/core'; import { useQuery } from '@tanstack/react-query'; import { useTranslation } from 'react-i18next'; import { useSession } from '../app/session'; import { AlbumGrid, Cover, TrackList } from '../entities/catalog'; import { usePlayer } from '../player/context'; import { playIcon, waveIcon } from '../shared/ui/icons'; import { Button } from '../shared/ui/ui'; import { NotFound } from './NotFound'; import s from './page.module.css'; import c from './catalog.module.css'; export function ArtistPage({ id }: { id: string }) { const { t } = useTranslation(); const session = useSession(); const player = usePlayer(); const artist = useQuery({ queryKey: ['artist', id], queryFn: async () => unwrap(await session.client.GET('/api/v1/artists/{id}', { params: { path: { id } } })), }); const top = useQuery({ queryKey: ['artist-top', id], queryFn: async () => unwrap(await session.client.GET('/api/v1/artists/{id}/top-tracks', { params: { path: { id }, query: { limit: 6 } } })).items, }); const albums = useQuery({ queryKey: ['artist-albums', id], queryFn: async () => unwrap(await session.client.GET('/api/v1/artists/{id}/albums', { params: { path: { id } } })).items, }); if (artist.isError) return ; const a = artist.data; const tracks = top.data ?? []; const ctx = { type: 'artist' as const, id, label: a?.name }; const own = albums.data?.filter((al) => al.artist.id === id) ?? []; const appears = albums.data?.filter((al) => al.artist.id !== id) ?? []; return (
{t('catalog.artist')}

{a?.name ?? '…'}

{a && ( {t('catalog.album_count', { count: a.album_count })} · {t('catalog.track_count', { count: a.track_count })} )} {a && (
{tracks.length > 0 && ( )}
)}
{tracks.length > 0 && (

{t('catalog.top_tracks')}

String(i + 1)} />
)} {own.length > 0 && (

{t('catalog.albums')}

)} {appears.length > 0 && (

{t('catalog.appears_on')}

)}
); }