diff --git a/src/renderer/features/artists/components/album-artist-detail-content.tsx b/src/renderer/features/artists/components/album-artist-detail-content.tsx index 9438e0aa4..755786073 100644 --- a/src/renderer/features/artists/components/album-artist-detail-content.tsx +++ b/src/renderer/features/artists/components/album-artist-detail-content.tsx @@ -667,30 +667,42 @@ const AlbumArtistMetadataFavoriteSongs = ({ const server = useCurrentServer(); const showRatings = useShowRatings(); const showFavorites = useShowFavorites(); - const showFavoriteAndRatingSegmentControl = - server?.type !== ServerType.JELLYFIN && showFavorites && showRatings; + const canShowRatings = showRatings && server?.type !== ServerType.JELLYFIN; + const showFavoriteAndRatingSegmentControl = showFavorites && canShowRatings; let favoriteSongsQueryTypeFilter = favoriteSongsQueryType; - if (showRatings && !showFavorites) { + if (canShowRatings && !showFavorites) { favoriteSongsQueryTypeFilter = 'rating'; - } else if (!showRatings && showFavorites) { + } else if (!canShowRatings && showFavorites) { favoriteSongsQueryTypeFilter = 'favorite'; } - const favoriteSongsQuery = useQuery({ + const favoritesQuery = useQuery({ ...artistsQueries.favoriteSongs({ query: { artistId: routeId, - type: favoriteSongsQueryTypeFilter, + type: 'favorite', }, serverId: serverId, }), + enabled: showFavorites, }); - const songs = useMemo( - () => favoriteSongsQuery.data?.items || [], - [favoriteSongsQuery.data?.items], - ); + const ratingsQuery = useQuery({ + ...artistsQueries.favoriteSongs({ + query: { + artistId: routeId, + type: 'rating', + }, + serverId: serverId, + }), + enabled: canShowRatings, + }); + + const activeSongsQuery = + favoriteSongsQueryTypeFilter === 'rating' ? ratingsQuery : favoritesQuery; + + const songs = useMemo(() => activeSongsQuery.data?.items || [], [activeSongsQuery.data?.items]); const columns = useMemo(() => { return tableConfig?.columns || []; @@ -751,10 +763,16 @@ const AlbumArtistMetadataFavoriteSongs = ({ onLongPress: () => handlePlay(LONG_PRESS_PLAY_BEHAVIOR[Play.LAST]), }); - const isLoading = favoriteSongsQuery.isLoading || !favoriteSongsQuery.data; + const isChecking = + (showFavorites && favoritesQuery.isLoading) || (canShowRatings && ratingsQuery.isLoading); + const isLoading = + activeSongsQuery.isLoading || (!activeSongsQuery.data && !activeSongsQuery.isError); + const hasAnyFavoriteSongs = + (favoritesQuery.data?.items?.length ?? 0) > 0 || + (ratingsQuery.data?.items?.length ?? 0) > 0; if (!isLoading && !tableConfig) return null; - if (!isLoading && songs.length === 0) return null; + if (!isChecking && !hasAnyFavoriteSongs) return null; const currentSongId = currentSong?.id; @@ -771,20 +789,22 @@ const AlbumArtistMetadataFavoriteSongs = ({