From ec04a63fe5f0e597890eee17be618dcf8a27c00a Mon Sep 17 00:00:00 2001 From: strecke <35091155+strecke@users.noreply.github.com> Date: Tue, 22 Sep 2026 18:39:51 +0200 Subject: [PATCH] fix(library): keep favorite songs mounted when empty (#2493) Prevent unmounting Favorite Songs when switching to an empty source (e.g. switching between favorites and ratings with 0 tracks). - Query favorites and ratings in parallel when capabilities allow - Only unmount when neither source has tracks - Display centered empty state string when active source has no tracks - Hide "View all" header button when there are no songs --- .../album-artist-detail-content.tsx | 142 +++++++++++------- 1 file changed, 88 insertions(+), 54 deletions(-) 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 = ({
- + {songs.length > 0 && ( + + )} {songs.length > 0 && ( @@ -911,35 +931,49 @@ const AlbumArtistMetadataFavoriteSongs = ({ tableColumnsData={SONG_TABLE_COLUMNS} /> - - 0 ? ( + - + itemCount={filteredSongs.length} + maxRows={5} + tableSize={tableConfig.size} + > + + + ) : ( +
+ + {t('common.noResultsFromQuery')} + +
+ )} ) : null}