mirror of
https://github.com/jeffvli/feishin.git
synced 2026-11-20 17:11:30 -08:00
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
This commit is contained in:
1 parent
ce421d2729
commit
ec04a63fe5
1 file changed
+88
-54
@@ -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 = ({
|
||||
</Group>
|
||||
<div className={styles.albumSectionDividerContainer}>
|
||||
<div className={styles.albumSectionDivider} />
|
||||
<Button
|
||||
component={Link}
|
||||
size="compact-md"
|
||||
to={generatePath(
|
||||
AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL_FAVORITE_SONGS,
|
||||
{
|
||||
albumArtistId: routeId,
|
||||
},
|
||||
)}
|
||||
uppercase
|
||||
variant="subtle"
|
||||
>
|
||||
{t('page.albumArtistDetail.viewAll')}
|
||||
</Button>
|
||||
{songs.length > 0 && (
|
||||
<Button
|
||||
component={Link}
|
||||
size="compact-md"
|
||||
to={generatePath(
|
||||
AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL_FAVORITE_SONGS,
|
||||
{
|
||||
albumArtistId: routeId,
|
||||
},
|
||||
)}
|
||||
uppercase
|
||||
variant="subtle"
|
||||
>
|
||||
{t('page.albumArtistDetail.viewAll')}
|
||||
</Button>
|
||||
)}
|
||||
{songs.length > 0 && (
|
||||
<ActionIconGroup>
|
||||
<PlayTooltip type={Play.NOW}>
|
||||
@@ -911,35 +931,49 @@ const AlbumArtistMetadataFavoriteSongs = ({
|
||||
tableColumnsData={SONG_TABLE_COLUMNS}
|
||||
/>
|
||||
</Group>
|
||||
<SongTableListContainer
|
||||
enableHeader={tableConfig.enableHeader}
|
||||
itemCount={filteredSongs.length}
|
||||
maxRows={5}
|
||||
tableSize={tableConfig.size}
|
||||
>
|
||||
<ItemTableList
|
||||
activeRowId={currentSongId}
|
||||
autoFitColumns={tableConfig.autoFitColumns}
|
||||
CellComponent={ItemTableListColumn}
|
||||
columns={columns}
|
||||
data={filteredSongs}
|
||||
enableAlternateRowColors={tableConfig.enableAlternateRowColors}
|
||||
enableDrag
|
||||
enableDragScroll={false}
|
||||
enableExpansion={false}
|
||||
{filteredSongs.length > 0 ? (
|
||||
<SongTableListContainer
|
||||
enableHeader={tableConfig.enableHeader}
|
||||
enableHorizontalBorders={tableConfig.enableHorizontalBorders}
|
||||
enableRowHoverHighlight={tableConfig.enableRowHoverHighlight}
|
||||
enableSelection
|
||||
enableSelectionDialog={false}
|
||||
enableVerticalBorders={tableConfig.enableVerticalBorders}
|
||||
itemType={LibraryItem.SONG}
|
||||
onColumnReordered={handleColumnReordered}
|
||||
onColumnResized={handleColumnResized}
|
||||
overrideControls={overrideControls}
|
||||
size={tableConfig.size}
|
||||
/>
|
||||
</SongTableListContainer>
|
||||
itemCount={filteredSongs.length}
|
||||
maxRows={5}
|
||||
tableSize={tableConfig.size}
|
||||
>
|
||||
<ItemTableList
|
||||
activeRowId={currentSongId}
|
||||
autoFitColumns={tableConfig.autoFitColumns}
|
||||
CellComponent={ItemTableListColumn}
|
||||
columns={columns}
|
||||
data={filteredSongs}
|
||||
enableAlternateRowColors={
|
||||
tableConfig.enableAlternateRowColors
|
||||
}
|
||||
enableDrag
|
||||
enableDragScroll={false}
|
||||
enableExpansion={false}
|
||||
enableHeader={tableConfig.enableHeader}
|
||||
enableHorizontalBorders={
|
||||
tableConfig.enableHorizontalBorders
|
||||
}
|
||||
enableRowHoverHighlight={
|
||||
tableConfig.enableRowHoverHighlight
|
||||
}
|
||||
enableSelection
|
||||
enableSelectionDialog={false}
|
||||
enableVerticalBorders={tableConfig.enableVerticalBorders}
|
||||
itemType={LibraryItem.SONG}
|
||||
onColumnReordered={handleColumnReordered}
|
||||
onColumnResized={handleColumnResized}
|
||||
overrideControls={overrideControls}
|
||||
size={tableConfig.size}
|
||||
/>
|
||||
</SongTableListContainer>
|
||||
) : (
|
||||
<Center py="xl" w="100%">
|
||||
<Text fw={500} isMuted isNoSelect size="sm">
|
||||
{t('common.noResultsFromQuery')}
|
||||
</Text>
|
||||
</Center>
|
||||
)}
|
||||
</>
|
||||
) : null}
|
||||
</Stack>
|
||||
|
||||
Reference in new issue
Block a user