2025-11-02 01:16:53 -07:00
|
|
|
import { useQuery } from '@tanstack/react-query';
|
2025-05-18 14:03:18 -07:00
|
|
|
import { forwardRef, Fragment, Ref } from 'react';
|
2024-09-01 19:42:01 -04:00
|
|
|
import { useTranslation } from 'react-i18next';
|
2023-01-12 18:43:25 -08:00
|
|
|
import { useParams } from 'react-router';
|
2025-05-18 14:03:18 -07:00
|
|
|
|
2025-11-02 01:16:53 -07:00
|
|
|
import { artistsQueries } from '/@/renderer/features/artists/api/artists-api';
|
2025-09-22 22:39:46 -07:00
|
|
|
import { LibraryHeader } from '/@/renderer/features/shared/components/library-header';
|
|
|
|
|
import { useSetRating } from '/@/renderer/features/shared/mutations/set-rating-mutation';
|
2023-01-12 18:43:25 -08:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2025-05-20 19:23:36 -07:00
|
|
|
import { useCurrentServer } from '/@/renderer/store';
|
2023-01-12 18:43:25 -08:00
|
|
|
import { formatDurationString } from '/@/renderer/utils';
|
2025-06-24 00:04:36 -07:00
|
|
|
import { Group } from '/@/shared/components/group/group';
|
|
|
|
|
import { Rating } from '/@/shared/components/rating/rating';
|
|
|
|
|
import { Stack } from '/@/shared/components/stack/stack';
|
|
|
|
|
import { Text } from '/@/shared/components/text/text';
|
2025-05-20 19:23:36 -07:00
|
|
|
import { LibraryItem, ServerType } from '/@/shared/types/domain-types';
|
2023-01-12 18:43:25 -08:00
|
|
|
|
|
|
|
|
interface AlbumArtistDetailHeaderProps {
|
2025-10-10 18:26:28 -07:00
|
|
|
background: {
|
|
|
|
|
background?: string;
|
|
|
|
|
blur: number;
|
|
|
|
|
loading: boolean;
|
|
|
|
|
};
|
2023-01-12 18:43:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AlbumArtistDetailHeader = forwardRef(
|
2025-10-10 18:26:28 -07:00
|
|
|
({ background }: AlbumArtistDetailHeaderProps, ref: Ref<HTMLDivElement>) => {
|
2025-05-06 14:43:42 -07:00
|
|
|
const { albumArtistId, artistId } = useParams() as {
|
|
|
|
|
albumArtistId?: string;
|
|
|
|
|
artistId?: string;
|
|
|
|
|
};
|
|
|
|
|
const routeId = (artistId || albumArtistId) as string;
|
2023-07-01 19:10:05 -07:00
|
|
|
const server = useCurrentServer();
|
2024-09-01 19:42:01 -04:00
|
|
|
const { t } = useTranslation();
|
2025-11-02 01:16:53 -07:00
|
|
|
const detailQuery = useQuery(
|
|
|
|
|
artistsQueries.albumArtistDetail({
|
|
|
|
|
query: { id: routeId },
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
}),
|
|
|
|
|
);
|
2023-01-12 18:43:25 -08:00
|
|
|
|
2025-05-07 19:53:23 -07:00
|
|
|
const albumCount = detailQuery?.data?.albumCount;
|
|
|
|
|
const songCount = detailQuery?.data?.songCount;
|
|
|
|
|
const duration = detailQuery?.data?.duration;
|
|
|
|
|
const durationEnabled = duration !== null && duration !== undefined;
|
|
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const metadataItems = [
|
|
|
|
|
{
|
2025-05-07 19:53:23 -07:00
|
|
|
enabled: albumCount !== null && albumCount !== undefined,
|
2023-07-01 19:10:05 -07:00
|
|
|
id: 'albumCount',
|
|
|
|
|
secondary: false,
|
2025-05-07 19:53:23 -07:00
|
|
|
value: t('entity.albumWithCount', { count: albumCount || 0 }),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
{
|
2025-05-07 19:53:23 -07:00
|
|
|
enabled: songCount !== null && songCount !== undefined,
|
2023-07-01 19:10:05 -07:00
|
|
|
id: 'songCount',
|
|
|
|
|
secondary: false,
|
2025-05-07 19:53:23 -07:00
|
|
|
value: t('entity.trackWithCount', { count: songCount || 0 }),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
{
|
2025-05-07 19:53:23 -07:00
|
|
|
enabled: durationEnabled,
|
2023-07-01 19:10:05 -07:00
|
|
|
id: 'duration',
|
|
|
|
|
secondary: true,
|
2025-05-07 19:53:23 -07:00
|
|
|
value: durationEnabled && formatDurationString(duration),
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
];
|
2023-01-12 18:43:25 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const updateRatingMutation = useSetRating({});
|
2023-02-05 05:19:01 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const handleUpdateRating = (rating: number) => {
|
|
|
|
|
if (!detailQuery?.data) return;
|
2023-02-05 05:19:01 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
updateRatingMutation.mutate({
|
|
|
|
|
query: {
|
|
|
|
|
item: [detailQuery.data],
|
|
|
|
|
rating,
|
|
|
|
|
},
|
|
|
|
|
serverId: detailQuery?.data.serverId,
|
|
|
|
|
});
|
|
|
|
|
};
|
2023-02-05 05:19:01 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const showRating = detailQuery?.data?.serverType === ServerType.NAVIDROME;
|
2023-02-05 05:19:01 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
2023-07-24 14:50:54 -07:00
|
|
|
<LibraryHeader
|
|
|
|
|
imageUrl={detailQuery?.data?.imageUrl}
|
|
|
|
|
item={{ route: AppRoute.LIBRARY_ALBUM_ARTISTS, type: LibraryItem.ALBUM_ARTIST }}
|
2025-05-18 14:03:18 -07:00
|
|
|
ref={ref}
|
2023-07-24 14:50:54 -07:00
|
|
|
title={detailQuery?.data?.name || ''}
|
2025-10-10 18:26:28 -07:00
|
|
|
{...background}
|
2023-07-24 14:50:54 -07:00
|
|
|
>
|
|
|
|
|
<Stack>
|
|
|
|
|
<Group>
|
|
|
|
|
{metadataItems
|
2024-09-26 04:23:08 +00:00
|
|
|
.filter((i) => i.enabled)
|
2023-07-24 14:50:54 -07:00
|
|
|
.map((item, index) => (
|
|
|
|
|
<Fragment key={`item-${item.id}-${index}`}>
|
2025-06-24 00:04:36 -07:00
|
|
|
{index > 0 && <Text isNoSelect>•</Text>}
|
|
|
|
|
<Text isMuted={item.secondary}>{item.value}</Text>
|
2023-07-24 14:50:54 -07:00
|
|
|
</Fragment>
|
|
|
|
|
))}
|
|
|
|
|
{showRating && (
|
|
|
|
|
<>
|
2025-06-24 00:04:36 -07:00
|
|
|
<Text isNoSelect>•</Text>
|
2023-07-24 14:50:54 -07:00
|
|
|
<Rating
|
2025-05-18 14:03:18 -07:00
|
|
|
onChange={handleUpdateRating}
|
2023-07-24 14:50:54 -07:00
|
|
|
readOnly={
|
2025-11-02 01:16:53 -07:00
|
|
|
detailQuery?.isFetching || updateRatingMutation.isPending
|
2023-07-24 14:50:54 -07:00
|
|
|
}
|
|
|
|
|
value={detailQuery?.data?.userRating || 0}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Group>
|
|
|
|
|
</Stack>
|
|
|
|
|
</LibraryHeader>
|
2023-07-01 19:10:05 -07:00
|
|
|
);
|
|
|
|
|
},
|
2023-01-12 18:43:25 -08:00
|
|
|
);
|