feishin/src/renderer/features/artists/routes/album-artist-detail-route.tsx

79 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-01-12 18:43:25 -08:00
import { useRef } from 'react';
import { useParams } from 'react-router';
import { NativeScrollArea } from '/@/renderer/components/native-scroll-area/native-scroll-area';
2023-01-12 18:43:25 -08:00
import { AlbumArtistDetailContent } from '/@/renderer/features/artists/components/album-artist-detail-content';
import { AlbumArtistDetailHeader } from '/@/renderer/features/artists/components/album-artist-detail-header';
import { useAlbumArtistDetail } from '/@/renderer/features/artists/queries/album-artist-detail-query';
import { usePlayQueueAdd } from '/@/renderer/features/player';
import { AnimatedPage, LibraryHeaderBar } from '/@/renderer/features/shared';
import { useFastAverageColor } from '/@/renderer/hooks';
import { useCurrentServer } from '/@/renderer/store';
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
2025-05-20 19:23:36 -07:00
import { LibraryItem } from '/@/shared/types/domain-types';
2023-01-12 18:43:25 -08:00
const AlbumArtistDetailRoute = () => {
2023-07-01 19:10:05 -07:00
const scrollAreaRef = useRef<HTMLDivElement>(null);
const headerRef = useRef<HTMLDivElement>(null);
const server = useCurrentServer();
2023-01-12 18:43:25 -08:00
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 handlePlayQueueAdd = usePlayQueueAdd();
const playButtonBehavior = usePlayButtonBehavior();
const detailQuery = useAlbumArtistDetail({
2025-05-06 14:43:42 -07:00
query: { id: routeId },
2023-07-01 19:10:05 -07:00
serverId: server?.id,
2023-01-12 18:43:25 -08:00
});
2025-06-20 17:57:15 -07:00
const { background, colorId } = useFastAverageColor({
2025-05-06 14:43:42 -07:00
id: routeId,
src: detailQuery.data?.imageUrl,
srcLoaded: !detailQuery.isLoading,
});
2023-07-01 19:10:05 -07:00
const handlePlay = () => {
handlePlayQueueAdd?.({
byItemType: {
2025-05-06 14:43:42 -07:00
id: [routeId],
2023-07-01 19:10:05 -07:00
type: LibraryItem.ALBUM_ARTIST,
},
playType: playButtonBehavior,
});
};
2023-01-12 18:43:25 -08:00
2023-07-01 19:10:05 -07:00
return (
2025-05-06 14:43:42 -07:00
<AnimatedPage key={`album-artist-detail-${routeId}`}>
2023-07-01 19:10:05 -07:00
<NativeScrollArea
pageHeaderProps={{
backgroundColor: background,
2023-07-01 19:10:05 -07:00
children: (
<LibraryHeaderBar>
<LibraryHeaderBar.PlayButton onClick={handlePlay} />
<LibraryHeaderBar.Title>
{detailQuery?.data?.name}
</LibraryHeaderBar.Title>
</LibraryHeaderBar>
),
2023-07-21 18:04:05 -07:00
offset: 200,
2023-07-01 19:10:05 -07:00
target: headerRef,
}}
ref={scrollAreaRef}
2023-07-01 19:10:05 -07:00
>
<AlbumArtistDetailHeader
background={background}
2025-06-20 17:57:15 -07:00
loading={!background || colorId !== routeId}
ref={headerRef}
2023-07-01 19:10:05 -07:00
/>
<AlbumArtistDetailContent background={background} />
2023-07-01 19:10:05 -07:00
</NativeScrollArea>
</AnimatedPage>
);
2023-01-12 18:43:25 -08:00
};
export default AlbumArtistDetailRoute;