import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { Play, UserCheck, UserPlus } from "lucide-react"; import { Link, useParams } from "react-router-dom"; import { artistsApi } from "../lib/api"; import { usePlayer } from "../store/player"; import { Cover } from "../components/Cover"; import { ShareButton } from "../components/ShareButton"; import { TrackRow } from "../components/TrackRow"; export function ArtistPage() { const { id = "" } = useParams(); const qc = useQueryClient(); const playQueue = usePlayer((s) => s.playQueue); const { data, isLoading } = useQuery({ queryKey: ["artist", id], queryFn: () => artistsApi.get(id), enabled: Boolean(id), }); const { data: tracks = [] } = useQuery({ queryKey: ["artist-tracks", id], queryFn: () => artistsApi.tracks(id), enabled: Boolean(id), }); const follow = useMutation({ mutationFn: () => (data?.following ? artistsApi.unfollow(id) : artistsApi.follow(id)), onSuccess: () => { void qc.invalidateQueries({ queryKey: ["artist", id] }); void qc.invalidateQueries({ queryKey: ["library"] }); }, }); if (isLoading) return

Загрузка...

; if (!data) return

Артист не найден.

; const { artist } = data; return (
Артист

{artist.name}

{artist.followersCount} подписчиков {artist.trackCount !== undefined && ` · ${artist.trackCount} треков`} {artist.country && ` · ${artist.country}`}

{artist.description && (

{artist.description}

)}
{data.albums.length > 0 && (

Альбомы

{data.albums.map((al) => (
{al.title}
{al.releaseDate?.slice(0, 4)}
))}
)}

Треки

{tracks.length ? (
{tracks.map((t, i) => ( ))}
) : (

Треков пока нет.

)}
); }