import { HeartFillIcon, HeartIcon } from '@primer/octicons-react' import { useEffect } from 'react' import { Link, useParams } from 'react-router-dom' import { JellyImg } from '../components/JellyImg' import { Loader } from '../components/Loader' import { MediaList } from '../components/MediaList' import { Squircle } from '../components/Squircle' import { MoreIcon } from '../components/SvgIcons' import { TrackList } from '../components/TrackList' import { useDropdownContext } from '../context/DropdownContext/DropdownContext' import { usePageTitle } from '../context/PageTitleContext/PageTitleContext' import { usePlaybackContext } from '../context/PlaybackContext/PlaybackContext' import { useJellyfinArtistData } from '../hooks/Jellyfin/useJellyfinArtistData' import { useJellyfinPlaylistsFeaturingArtist } from '../hooks/Jellyfin/useJellyfinPlaylistsFeaturingArtist' import { useFavorites } from '../hooks/useFavorites' import { formatDurationReadable } from '../utils/formatDurationReadable' import './Artist.css' export const Artist = () => { const playback = usePlaybackContext() const { artistId } = useParams<{ artistId: string }>() const { artist, tracks, albums, appearsInAlbums, totalTrackCount, totalPlaytime, totalPlays, totalAlbumCount, loading, error, } = useJellyfinArtistData(artistId!) const { playlists, loading: playlistsLoading, error: playlistsError, } = useJellyfinPlaylistsFeaturingArtist(artistId!) const { setPageTitle } = usePageTitle() const { isOpen, selectedItem, onContextMenu } = useDropdownContext() const { addToFavorites, removeFromFavorites } = useFavorites() useEffect(() => { if (artist) { setPageTitle(artist.Name) } return () => { setPageTitle('') } }, [artist, setPageTitle]) if (loading) { return } if (error || !artist) { return
{error || 'Artist not found'}
} const topSongs = tracks.slice(0, 5) const genres = artist.Genres || [] const handleMoreClick = (e: React.MouseEvent) => { e.stopPropagation() onContextMenu(e, { item: artist }, true, { add_to_favorite: true, remove_from_favorite: true }) } return (
{artist.Name}
{genres.length > 0 && (
{genres.slice(0, 6).map((genre, index) => ( {genre} {index < genres.slice(0, 6).length - 1 && ', '} ))}
)}
{totalTrackCount}{' '} {totalTrackCount === 1 ? 'Track' : 'Tracks'}
{totalAlbumCount}{' '} {totalAlbumCount === 1 ? 'Album' : 'Albums'}
{formatDurationReadable(totalPlaytime)} Total
{totalPlays > 0 && ( <>
{totalPlays} {totalPlays === 1 ? 'Play' : 'Plays'}
)}
{ playback.setCurrentPlaylistSimple({ playlist: tracks, title: artist.Name }) playback.playTrack(0) }} >
Play
{ if (artist?.Id) { try { if (artist.UserData?.IsFavorite) { await removeFromFavorites(artist) } else { await addToFavorites(artist) } } catch (error) { console.error('Failed to update favorite status:', error) } } }} > {artist.UserData?.IsFavorite ? : }
{topSongs.length > 0 && (
)} {albums.length > 0 && (
Albums
Complete discography
)} {appearsInAlbums.length > 0 && (
Appears In
Additional recordings
)} {playlists.length > 0 && (
{playlistsLoading ? ( ) : ( <>
Playlists
Included in curated collections
)}
) }