2023-10-29 03:00:01 +00:00
|
|
|
import { forwardRef, Fragment, Ref } from 'react';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { Group, Rating, Stack } from '@mantine/core';
|
2023-01-12 18:43:25 -08:00
|
|
|
import { useParams } from 'react-router';
|
2023-02-05 05:19:01 -08:00
|
|
|
import { LibraryItem, ServerType } from '/@/renderer/api/types';
|
2023-01-12 18:43:25 -08:00
|
|
|
import { Text } from '/@/renderer/components';
|
|
|
|
|
import { useAlbumArtistDetail } from '/@/renderer/features/artists/queries/album-artist-detail-query';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { LibraryHeader, useSetRating } from '/@/renderer/features/shared';
|
2023-01-12 18:43:25 -08:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
|
|
|
|
import { formatDurationString } from '/@/renderer/utils';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { useCurrentServer } from '../../../store/auth.store';
|
2023-01-12 18:43:25 -08:00
|
|
|
|
|
|
|
|
interface AlbumArtistDetailHeaderProps {
|
2023-07-01 19:10:05 -07:00
|
|
|
background: string;
|
2023-01-12 18:43:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const AlbumArtistDetailHeader = forwardRef(
|
2023-07-01 19:10:05 -07:00
|
|
|
({ background }: AlbumArtistDetailHeaderProps, ref: Ref<HTMLDivElement>) => {
|
|
|
|
|
const { albumArtistId } = useParams() as { albumArtistId: string };
|
|
|
|
|
const server = useCurrentServer();
|
|
|
|
|
const detailQuery = useAlbumArtistDetail({
|
|
|
|
|
query: { id: albumArtistId },
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2023-01-12 18:43:25 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const metadataItems = [
|
|
|
|
|
{
|
|
|
|
|
id: 'albumCount',
|
|
|
|
|
secondary: false,
|
|
|
|
|
value: detailQuery?.data?.albumCount && `${detailQuery?.data?.albumCount} albums`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'songCount',
|
|
|
|
|
secondary: false,
|
|
|
|
|
value: detailQuery?.data?.songCount && `${detailQuery?.data?.songCount} songs`,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'duration',
|
|
|
|
|
secondary: true,
|
|
|
|
|
value:
|
|
|
|
|
detailQuery?.data?.duration && formatDurationString(detailQuery.data.duration),
|
|
|
|
|
},
|
|
|
|
|
];
|
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
|
|
|
|
|
ref={ref}
|
|
|
|
|
background={background}
|
|
|
|
|
imageUrl={detailQuery?.data?.imageUrl}
|
|
|
|
|
item={{ route: AppRoute.LIBRARY_ALBUM_ARTISTS, type: LibraryItem.ALBUM_ARTIST }}
|
|
|
|
|
title={detailQuery?.data?.name || ''}
|
|
|
|
|
>
|
|
|
|
|
<Stack>
|
|
|
|
|
<Group>
|
|
|
|
|
{metadataItems
|
|
|
|
|
.filter((i) => i.value)
|
|
|
|
|
.map((item, index) => (
|
|
|
|
|
<Fragment key={`item-${item.id}-${index}`}>
|
|
|
|
|
{index > 0 && <Text $noSelect>•</Text>}
|
|
|
|
|
<Text $secondary={item.secondary}>{item.value}</Text>
|
|
|
|
|
</Fragment>
|
|
|
|
|
))}
|
|
|
|
|
{showRating && (
|
|
|
|
|
<>
|
|
|
|
|
<Text $noSelect>•</Text>
|
|
|
|
|
<Rating
|
|
|
|
|
readOnly={
|
|
|
|
|
detailQuery?.isFetching || updateRatingMutation.isLoading
|
|
|
|
|
}
|
|
|
|
|
value={detailQuery?.data?.userRating || 0}
|
|
|
|
|
onChange={handleUpdateRating}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
</Group>
|
|
|
|
|
</Stack>
|
|
|
|
|
</LibraryHeader>
|
2023-07-01 19:10:05 -07:00
|
|
|
);
|
|
|
|
|
},
|
2023-01-12 18:43:25 -08:00
|
|
|
);
|