'use client'; import { useEffect, useState } from 'react'; import { useParams } from 'next/navigation'; import { Album, Artist } from '@/lib/navidrome'; import { useNavidrome } from '@/app/components/NavidromeContext'; import { AlbumArtwork } from '@/app/components/album-artwork'; import Image from 'next/image'; import { Button } from '@/components/ui/button'; import { Heart } from 'lucide-react'; import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'; import Loading from '@/app/components/loading'; import { getNavidromeAPI } from '@/lib/navidrome'; export default function ArtistPage() { const { artist: artistId } = useParams(); const [isStarred, setIsStarred] = useState(false); const [artistAlbums, setArtistAlbums] = useState([]); const [loading, setLoading] = useState(true); const [artist, setArtist] = useState(null); const { getArtist, starItem, unstarItem } = useNavidrome(); const api = getNavidromeAPI(); useEffect(() => { const fetchArtistData = async () => { setLoading(true); try { if (artistId) { const artistData = await getArtist(artistId as string); setArtist(artistData.artist); setArtistAlbums(artistData.albums); setIsStarred(!!artistData.artist.starred); } } catch (error) { console.error('Failed to fetch artist data:', error); } setLoading(false); }; fetchArtistData(); }, [artistId, getArtist]); const handleStar = async () => { if (!artist) return; try { if (isStarred) { await unstarItem(artist.id, 'artist'); setIsStarred(false); } else { await starItem(artist.id, 'artist'); setIsStarred(true); } } catch (error) { console.error('Failed to star/unstar artist:', error); } }; if (loading) { return ; } if (!artist || artistAlbums.length === 0) { return (

No albums found for this artist

); } // Get artist image URL with proper fallback const artistImageUrl = artist.coverArt ? api.getCoverArtUrl(artist.coverArt, 300) : '/default-user.jpg'; return (
{/* Artist Header */}
{artist.name}

{artist.name}

{artist.albumCount} albums

{/* Albums Section */}

Albums

{artistAlbums.map((album) => ( ))}
); }