update album artist page

This commit is contained in:
jeffvli
2025-11-28 22:59:40 -08:00
parent 663fdd426f
commit a18d2ee305
5 changed files with 345 additions and 222 deletions
@@ -1,12 +1,12 @@
.content-container { .content-container {
position: relative; position: relative;
z-index: 0; z-index: 0;
container-type: inline-size;
} }
.detail-container { .detail-container {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: var(--theme-spacing-lg); gap: var(--theme-spacing-2xl);
padding: 1rem 2rem 5rem; padding: 1rem 2rem 5rem;
overflow: hidden;
} }
@@ -1,4 +1,4 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery, useSuspenseQuery } from '@tanstack/react-query';
import { Suspense, useMemo } from 'react'; import { Suspense, useMemo } from 'react';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { createSearchParams, generatePath, Link, useParams } from 'react-router'; import { createSearchParams, generatePath, Link, useParams } from 'react-router';
@@ -25,15 +25,253 @@ import { Spinner } from '/@/shared/components/spinner/spinner';
import { Spoiler } from '/@/shared/components/spoiler/spoiler'; import { Spoiler } from '/@/shared/components/spoiler/spoiler';
import { Stack } from '/@/shared/components/stack/stack'; import { Stack } from '/@/shared/components/stack/stack';
import { TextTitle } from '/@/shared/components/text-title/text-title'; import { TextTitle } from '/@/shared/components/text-title/text-title';
import { Text } from '/@/shared/components/text/text';
import { import {
AlbumArtist, AlbumArtist,
AlbumListSort, AlbumListSort,
LibraryItem, LibraryItem,
ServerType, ServerType,
SortOrder, SortOrder,
TopSongListResponse,
} from '/@/shared/types/domain-types'; } from '/@/shared/types/domain-types';
import { Play } from '/@/shared/types/types'; import { Play } from '/@/shared/types/types';
interface AlbumArtistActionButtonsProps {
albumCount: null | number | undefined;
artistDiscographyLink: string;
artistSongsLink: string;
onFavorite: () => void;
onMoreOptions: (e: React.MouseEvent<HTMLButtonElement>) => void;
onPlay: () => void;
userFavorite?: boolean;
}
const AlbumArtistActionButtons = ({
albumCount,
artistDiscographyLink,
artistSongsLink,
onFavorite,
onMoreOptions,
onPlay,
userFavorite,
}: AlbumArtistActionButtonsProps) => {
const { t } = useTranslation();
return (
<>
<Group gap="md">
<DefaultPlayButton disabled={albumCount === 0} onClick={onPlay} />
<Group gap="xs">
<ActionIcon
icon="favorite"
iconProps={{
fill: userFavorite ? 'primary' : undefined,
}}
onClick={onFavorite}
size="lg"
variant="transparent"
/>
<ActionIcon
icon="ellipsisHorizontal"
onClick={onMoreOptions}
size="lg"
variant="transparent"
/>
</Group>
</Group>
<Group gap="md">
<Button
component={Link}
size="compact-md"
to={artistDiscographyLink}
variant="subtle"
>
{String(t('page.albumArtistDetail.viewDiscography')).toUpperCase()}
</Button>
<Button component={Link} size="compact-md" to={artistSongsLink} variant="subtle">
{String(t('page.albumArtistDetail.viewAllTracks')).toUpperCase()}
</Button>
</Group>
</>
);
};
interface AlbumArtistMetadataGenresProps {
genres?: Array<{ id: string; name: string }>;
}
const AlbumArtistMetadataGenres = ({ genres }: AlbumArtistMetadataGenresProps) => {
const { t } = useTranslation();
const genrePath = useGenreRoute();
if (!genres || genres.length === 0) return null;
return (
<Stack gap="xs">
<Text fw={600} isNoSelect size="sm" tt="uppercase">
{t('entity.genre', {
count: genres.length,
})}
</Text>
<Group gap="sm">
{genres.map((genre) => (
<Button
component={Link}
key={`genre-${genre.id}`}
radius="md"
size="compact-md"
to={generatePath(genrePath, {
albumArtistId: null,
albumId: null,
artistId: null,
genreId: genre.id,
itemType: null,
playlistId: null,
})}
variant="outline"
>
{genre.name}
</Button>
))}
</Group>
</Stack>
);
};
interface AlbumArtistMetadataBiographyProps {
artistName?: string;
biography: null | string | undefined;
}
const AlbumArtistMetadataBiography = ({
artistName,
biography,
}: AlbumArtistMetadataBiographyProps) => {
const { t } = useTranslation();
if (!biography) return null;
const sanitizedBiography = sanitize(biography);
return (
<section style={{ maxWidth: '1280px' }}>
<TextTitle fw={700} order={2}>
{t('page.albumArtistDetail.about', {
artist: artistName,
})}
</TextTitle>
<Spoiler dangerouslySetInnerHTML={{ __html: sanitizedBiography }} />
</section>
);
};
interface AlbumArtistMetadataTopSongsProps {
routeId: string;
topSongsQuery: ReturnType<typeof useQuery<TopSongListResponse>>;
}
const AlbumArtistMetadataTopSongs = ({
routeId,
topSongsQuery,
}: AlbumArtistMetadataTopSongsProps) => {
const { t } = useTranslation();
if (!topSongsQuery?.data?.items?.length) return null;
return (
<section>
<Group justify="space-between" wrap="nowrap">
<Group align="flex-end" wrap="nowrap">
<TextTitle fw={700} order={2}>
{t('page.albumArtistDetail.topSongs', {
postProcess: 'sentenceCase',
})}
</TextTitle>
<Button
component={Link}
size="compact-md"
to={generatePath(AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL_TOP_SONGS, {
albumArtistId: routeId,
})}
uppercase
variant="subtle"
>
{t('page.albumArtistDetail.viewAll', {
postProcess: 'sentenceCase',
})}
</Button>
</Group>
</Group>
</section>
);
};
interface AlbumArtistMetadataExternalLinksProps {
artistName?: string;
externalLinks: boolean;
lastFM: boolean;
mbzId?: null | string;
musicBrainz: boolean;
}
const AlbumArtistMetadataExternalLinks = ({
artistName,
externalLinks,
lastFM,
mbzId,
musicBrainz,
}: AlbumArtistMetadataExternalLinksProps) => {
const { t } = useTranslation();
if (!externalLinks || (!lastFM && !musicBrainz)) return null;
return (
<Stack gap="xs">
<Text fw={600} isNoSelect size="sm" tt="uppercase">
{t('common.externalLinks', {
postProcess: 'sentenceCase',
})}
</Text>
<Group gap="sm">
{lastFM && (
<ActionIcon
component="a"
href={`https://www.last.fm/music/${encodeURIComponent(artistName || '')}`}
icon="brandLastfm"
iconProps={{
fill: 'default',
size: 'xl',
}}
rel="noopener noreferrer"
target="_blank"
tooltip={{
label: t('action.openIn.lastfm'),
}}
variant="subtle"
/>
)}
{mbzId && musicBrainz ? (
<ActionIcon
component="a"
href={`https://musicbrainz.org/artist/${mbzId}`}
icon="brandMusicBrainz"
iconProps={{
fill: 'default',
size: 'xl',
}}
rel="noopener noreferrer"
target="_blank"
tooltip={{
label: t('action.openIn.musicbrainz'),
}}
variant="subtle"
/>
) : null}
</Group>
</Stack>
);
};
export const AlbumArtistDetailContent = () => { export const AlbumArtistDetailContent = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { artistItems, externalLinks, lastFM, musicBrainz } = useGeneralSettings(); const { artistItems, externalLinks, lastFM, musicBrainz } = useGeneralSettings();
@@ -42,10 +280,9 @@ export const AlbumArtistDetailContent = () => {
artistId?: string; artistId?: string;
}; };
const routeId = (artistId || albumArtistId) as string; const routeId = (artistId || albumArtistId) as string;
const { ref } = useContainerQuery(); const { ref, ...cq } = useContainerQuery();
const { addToQueueByFetch, setFavorite } = usePlayer(); const { addToQueueByFetch, setFavorite } = usePlayer();
const server = useCurrentServer(); const server = useCurrentServer();
const genrePath = useGenreRoute();
const [enabledItem, itemOrder] = useMemo(() => { const [enabledItem, itemOrder] = useMemo(() => {
const enabled: { [key in ArtistItem]?: boolean } = {}; const enabled: { [key in ArtistItem]?: boolean } = {};
@@ -59,7 +296,7 @@ export const AlbumArtistDetailContent = () => {
return [enabled, order]; return [enabled, order];
}, [artistItems]); }, [artistItems]);
const detailQuery = useQuery( const detailQuery = useSuspenseQuery(
artistsQueries.albumArtistDetail({ artistsQueries.albumArtistDetail({
query: { id: routeId }, query: { id: routeId },
serverId: server?.id, serverId: server?.id,
@@ -73,23 +310,23 @@ export const AlbumArtistDetailContent = () => {
}, },
)}?${createSearchParams({ )}?${createSearchParams({
artistId: routeId, artistId: routeId,
artistName: detailQuery?.data?.name || '', artistName: detailQuery.data?.name || '',
})}`; })}`;
const artistSongsLink = `${generatePath(AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL_SONGS, { const artistSongsLink = `${generatePath(AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL_SONGS, {
albumArtistId: routeId, albumArtistId: routeId,
})}?${createSearchParams({ })}?${createSearchParams({
artistId: routeId, artistId: routeId,
artistName: detailQuery?.data?.name || '', artistName: detailQuery.data?.name || '',
})}`; })}`;
const topSongsQuery = useQuery( const topSongsQuery = useQuery(
artistsQueries.topSongs({ artistsQueries.topSongs({
options: { options: {
enabled: !!detailQuery?.data?.name && enabledItem.topSongs, enabled: !!detailQuery.data?.name && enabledItem.topSongs,
}, },
query: { query: {
artist: detailQuery?.data?.name || '', artist: detailQuery.data?.name || '',
artistId: routeId, artistId: routeId,
}, },
serverId: server?.id, serverId: server?.id,
@@ -106,6 +343,7 @@ export const AlbumArtistDetailContent = () => {
artistIds: routeId ? [routeId] : undefined, artistIds: routeId ? [routeId] : undefined,
compilation: false, compilation: false,
}, },
rowCount: 2,
sortBy: AlbumListSort.RELEASE_DATE, sortBy: AlbumListSort.RELEASE_DATE,
sortOrder: SortOrder.DESC, sortOrder: SortOrder.DESC,
title: ( title: (
@@ -136,6 +374,7 @@ export const AlbumArtistDetailContent = () => {
artistIds: routeId ? [routeId] : undefined, artistIds: routeId ? [routeId] : undefined,
compilation: true, compilation: true,
}, },
rowCount: 1,
sortBy: AlbumListSort.RELEASE_DATE, sortBy: AlbumListSort.RELEASE_DATE,
sortOrder: SortOrder.DESC, sortOrder: SortOrder.DESC,
title: ( title: (
@@ -146,10 +385,11 @@ export const AlbumArtistDetailContent = () => {
uniqueId: 'compilationAlbums', uniqueId: 'compilationAlbums',
}, },
{ {
data: (detailQuery?.data?.similarArtists || []) as AlbumArtist[], data: (detailQuery.data?.similarArtists || []) as AlbumArtist[],
isHidden: !detailQuery?.data?.similarArtists || !enabledItem.similarArtists, isHidden: !detailQuery.data?.similarArtists || !enabledItem.similarArtists,
itemType: LibraryItem.ALBUM_ARTIST, itemType: LibraryItem.ALBUM_ARTIST,
order: itemOrder.similarArtists, order: itemOrder.similarArtists,
rowCount: 1,
title: ( title: (
<TextTitle fw={700} order={2}> <TextTitle fw={700} order={2}>
{t('page.albumArtistDetail.relatedArtists', { {t('page.albumArtistDetail.relatedArtists', {
@@ -162,7 +402,7 @@ export const AlbumArtistDetailContent = () => {
]; ];
}, [ }, [
artistDiscographyLink, artistDiscographyLink,
detailQuery?.data?.similarArtists, detailQuery.data?.similarArtists,
enabledItem.compilations, enabledItem.compilations,
enabledItem.recentAlbums, enabledItem.recentAlbums,
enabledItem.similarArtists, enabledItem.similarArtists,
@@ -187,7 +427,7 @@ export const AlbumArtistDetailContent = () => {
}; };
const handleFavorite = () => { const handleFavorite = () => {
if (!detailQuery?.data) return; if (!detailQuery.data) return;
setFavorite( setFavorite(
detailQuery.data._serverId, detailQuery.data._serverId,
[detailQuery.data.id], [detailQuery.data.id],
@@ -197,221 +437,105 @@ export const AlbumArtistDetailContent = () => {
}; };
const handleMoreOptions = (e: React.MouseEvent<HTMLButtonElement>) => { const handleMoreOptions = (e: React.MouseEvent<HTMLButtonElement>) => {
if (!detailQuery?.data) return; if (!detailQuery.data) return;
ContextMenuController.call({ ContextMenuController.call({
cmd: { items: [detailQuery.data], type: LibraryItem.ALBUM_ARTIST }, cmd: { items: [detailQuery.data], type: LibraryItem.ALBUM_ARTIST },
event: e, event: e,
}); });
}; };
const albumCount = detailQuery?.data?.albumCount; const albumCount = detailQuery.data?.albumCount;
const biography =
detailQuery.data?.biography && enabledItem.biography ? detailQuery.data.biography : null;
const showGenres = detailQuery.data?.genres ? detailQuery.data.genres.length !== 0 : false;
const mbzId = detailQuery.data?.mbz;
const biography = useMemo(() => { // Calculate order for genres and external links (show before other sections)
const bio = detailQuery?.data?.biography; // Use a very low order number to ensure they appear first
const genresOrder = 0;
if (!bio || !enabledItem.biography) return null; const externalLinksOrder = 0.5;
return sanitize(bio);
}, [detailQuery?.data?.biography, enabledItem.biography]);
const showTopSongs = topSongsQuery?.data?.items?.length && enabledItem.topSongs;
const showGenres = detailQuery?.data?.genres ? detailQuery?.data?.genres.length !== 0 : false;
const mbzId = detailQuery?.data?.mbz;
const isLoading =
detailQuery?.isLoading ||
(server?.type === ServerType.NAVIDROME && enabledItem.topSongs && topSongsQuery?.isLoading);
if (isLoading) return <div className={styles.contentContainer} ref={ref} />;
return ( return (
<div className={styles.contentContainer} ref={ref}> <div className={styles.contentContainer} ref={ref}>
<div className={styles.detailContainer}> <div className={styles.detailContainer}>
<Group gap="md"> <AlbumArtistActionButtons
<DefaultPlayButton albumCount={albumCount}
disabled={albumCount === 0} artistDiscographyLink={artistDiscographyLink}
onClick={() => handlePlay(playButtonBehavior)} artistSongsLink={artistSongsLink}
/> onFavorite={handleFavorite}
<Group gap="xs"> onMoreOptions={handleMoreOptions}
<ActionIcon onPlay={() => handlePlay(playButtonBehavior)}
icon="favorite" userFavorite={detailQuery.data?.userFavorite}
iconProps={{ />
fill: detailQuery?.data?.userFavorite ? 'primary' : undefined,
}}
onClick={handleFavorite}
size="lg"
variant="transparent"
/>
<ActionIcon
icon="ellipsisHorizontal"
onClick={handleMoreOptions}
size="lg"
variant="transparent"
/>
</Group>
</Group>
<Group gap="md">
<Button
component={Link}
size="compact-md"
to={artistDiscographyLink}
variant="subtle"
>
{String(t('page.albumArtistDetail.viewDiscography')).toUpperCase()}
</Button>
<Button
component={Link}
size="compact-md"
to={artistSongsLink}
variant="subtle"
>
{String(t('page.albumArtistDetail.viewAllTracks')).toUpperCase()}
</Button>
</Group>
{showGenres ? (
<section>
<Group gap="sm">
{detailQuery?.data?.genres?.map((genre) => (
<Button
component={Link}
key={`genre-${genre.id}`}
radius="md"
size="compact-md"
to={generatePath(genrePath, {
genreId: genre.id,
})}
variant="outline"
>
{genre.name}
</Button>
))}
</Group>
</section>
) : null}
{externalLinks && (lastFM || musicBrainz) ? (
<section>
<Group gap="sm">
{lastFM && (
<ActionIcon
component="a"
href={`https://www.last.fm/music/${encodeURIComponent(
detailQuery?.data?.name || '',
)}`}
icon="brandLastfm"
iconProps={{
fill: 'default',
size: 'xl',
}}
rel="noopener noreferrer"
target="_blank"
tooltip={{
label: t('action.openIn.lastfm'),
}}
variant="subtle"
/>
)}
{mbzId && musicBrainz ? (
<ActionIcon
component="a"
href={`https://musicbrainz.org/artist/${mbzId}`}
icon="brandMusicBrainz"
iconProps={{
fill: 'default',
size: 'xl',
}}
rel="noopener noreferrer"
target="_blank"
tooltip={{
label: t('action.openIn.musicbrainz'),
}}
variant="subtle"
/>
) : null}
</Group>
</section>
) : null}
<Grid gutter="xl"> <Grid gutter="xl">
{biography ? ( {showGenres && (
<Grid.Col order={genresOrder} span={12}>
<AlbumArtistMetadataGenres genres={detailQuery.data?.genres} />
</Grid.Col>
)}
{externalLinks && (lastFM || musicBrainz) && (
<Grid.Col order={externalLinksOrder} span={12}>
<AlbumArtistMetadataExternalLinks
artistName={detailQuery.data?.name}
externalLinks={externalLinks}
lastFM={lastFM}
mbzId={mbzId}
musicBrainz={musicBrainz}
/>
</Grid.Col>
)}
{biography && (
<Grid.Col order={itemOrder.biography} span={12}> <Grid.Col order={itemOrder.biography} span={12}>
<section style={{ maxWidth: '1280px' }}> <AlbumArtistMetadataBiography
<TextTitle fw={700} order={2}> artistName={detailQuery.data?.name}
{t('page.albumArtistDetail.about', { biography={biography}
artist: detailQuery?.data?.name, />
})}
</TextTitle>
<Spoiler dangerouslySetInnerHTML={{ __html: biography }} />
</section>
</Grid.Col> </Grid.Col>
) : null} )}
{showTopSongs ? ( {Boolean(topSongsQuery?.data?.items?.length) && enabledItem.topSongs && (
<Grid.Col order={itemOrder.topSongs} span={12}> <Grid.Col order={itemOrder.topSongs} span={12}>
<section> <AlbumArtistMetadataTopSongs
<Group justify="space-between" wrap="nowrap"> routeId={routeId}
<Group align="flex-end" wrap="nowrap"> topSongsQuery={topSongsQuery}
<TextTitle fw={700} order={2}> />
{t('page.albumArtistDetail.topSongs', {
postProcess: 'sentenceCase',
})}
</TextTitle>
<Button
component={Link}
size="compact-md"
to={generatePath(
AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL_TOP_SONGS,
{
albumArtistId: routeId,
},
)}
uppercase
variant="subtle"
>
{t('page.albumArtistDetail.viewAll', {
postProcess: 'sentenceCase',
})}
</Button>
</Group>
</Group>
</section>
</Grid.Col> </Grid.Col>
) : null} )}
{cq.height || cq.width
{carousels ? carousels
.filter((c) => !c.isHidden) .filter((c) => !c.isHidden)
.map((carousel) => ( .map((carousel) => (
<Grid.Col <Grid.Col
key={`carousel-${carousel.uniqueId}`} key={`carousel-${carousel.uniqueId}`}
order={carousel.order} order={carousel.order}
span={12} span={12}
> >
<section> <Suspense fallback={<Spinner container />}>
<Stack gap="xl"> {carousel.itemType === LibraryItem.ALBUM ? (
{carousel.itemType === LibraryItem.ALBUM ? ( 'query' in carousel &&
'query' in carousel && carousel.query &&
carousel.query && carousel.sortBy &&
carousel.sortBy && carousel.sortOrder ? (
carousel.sortOrder ? ( <AlbumInfiniteCarousel
<Suspense fallback={<Spinner container />}> query={carousel.query}
<AlbumInfiniteCarousel rowCount={carousel.rowCount}
query={carousel.query} sortBy={carousel.sortBy}
rowCount={1} sortOrder={carousel.sortOrder}
sortBy={carousel.sortBy} title={carousel.title}
sortOrder={carousel.sortOrder} />
title={carousel.title} ) : null
/> ) : carousel.itemType === LibraryItem.ALBUM_ARTIST ? (
</Suspense> 'data' in carousel && carousel.data ? (
) : null <AlbumArtistGridCarousel
) : carousel.itemType === LibraryItem.ALBUM_ARTIST ? ( data={carousel.data}
'data' in carousel && carousel.data ? ( rowCount={carousel.rowCount}
<AlbumArtistGridCarousel title={carousel.title}
data={carousel.data} />
rowCount={1} ) : null
title={carousel.title} ) : null}
/> </Suspense>
) : null </Grid.Col>
) : null} ))
</Stack> : null}
</section>
</Grid.Col>
))}
</Grid> </Grid>
</div> </div>
</div> </div>
@@ -1,4 +1,4 @@
import { useQuery } from '@tanstack/react-query'; import { useSuspenseQuery } from '@tanstack/react-query';
import { useRef } from 'react'; import { useRef } from 'react';
import { useLocation, useParams } from 'react-router'; import { useLocation, useParams } from 'react-router';
@@ -33,11 +33,8 @@ const AlbumArtistDetailRoute = () => {
const location = useLocation(); const location = useLocation();
const detailQuery = useQuery({ const detailQuery = useSuspenseQuery({
...artistsQueries.albumArtistDetail({ ...artistsQueries.albumArtistDetail({ query: { id: routeId }, serverId: server?.id }),
query: { id: routeId },
serverId: server?.id,
}),
initialData: location.state?.item, initialData: location.state?.item,
staleTime: 0, staleTime: 0,
}); });
@@ -49,6 +46,7 @@ const AlbumArtistDetailRoute = () => {
}); });
const background = backgroundColor; const background = backgroundColor;
const showBlurredImage = Boolean(detailQuery.data?.imageUrl) && artistBackground; const showBlurredImage = Boolean(detailQuery.data?.imageUrl) && artistBackground;
return ( return (
@@ -61,6 +59,7 @@ const AlbumArtistDetailRoute = () => {
<LibraryHeaderBar.PlayButton <LibraryHeaderBar.PlayButton
ids={[routeId]} ids={[routeId]}
itemType={LibraryItem.ALBUM_ARTIST} itemType={LibraryItem.ALBUM_ARTIST}
variant="default"
/> />
<LibraryHeaderBar.Title> <LibraryHeaderBar.Title>
{detailQuery?.data?.name} {detailQuery?.data?.name}
@@ -72,11 +71,11 @@ const AlbumArtistDetailRoute = () => {
}} }}
ref={scrollAreaRef} ref={scrollAreaRef}
> >
{showBlurredImage && detailQuery.data?.imageUrl ? ( {showBlurredImage ? (
<LibraryBackgroundImage <LibraryBackgroundImage
blur={artistBackgroundBlur} blur={artistBackgroundBlur}
headerRef={headerRef} headerRef={headerRef}
imageUrl={detailQuery.data.imageUrl} imageUrl={detailQuery.data?.imageUrl || ''}
/> />
) : ( ) : (
<LibraryBackgroundOverlay backgroundColor={background} headerRef={headerRef} /> <LibraryBackgroundOverlay backgroundColor={background} headerRef={headerRef} />
@@ -10,7 +10,6 @@
width: 100%; width: 100%;
max-width: 100%; max-width: 100%;
height: auto; height: auto;
min-height: 340px;
padding: 2rem 1rem; padding: 2rem 1rem;
:global(.item-image-placeholder) { :global(.item-image-placeholder) {
@@ -101,6 +101,7 @@ export const LibraryHeader = forwardRef(
alt="cover" alt="cover"
className={styles.image} className={styles.image}
containerClassName={styles.image} containerClassName={styles.image}
key={imageUrl}
loading="eager" loading="eager"
onError={onImageError} onError={onImageError}
src={imageUrl || ''} src={imageUrl || ''}