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

69 lines
2.7 KiB
TypeScript
Raw Normal View History

2023-01-12 18:43:25 -08:00
import { NativeScrollArea } from '/@/renderer/components';
import { AnimatedPage, LibraryHeaderBar } from '/@/renderer/features/shared';
import { useRef } from 'react';
import { useParams } from 'react-router';
import { useFastAverageColor } from '/@/renderer/hooks';
import { usePlayQueueAdd } from '/@/renderer/features/player';
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
import { LibraryItem } from '/@/renderer/api/types';
import { useAlbumArtistDetail } from '/@/renderer/features/artists/queries/album-artist-detail-query';
import { AlbumArtistDetailHeader } from '/@/renderer/features/artists/components/album-artist-detail-header';
import { AlbumArtistDetailContent } from '/@/renderer/features/artists/components/album-artist-detail-content';
import { useCurrentServer } from '/@/renderer/store';
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
2023-07-01 19:10:05 -07:00
const { albumArtistId } = useParams() as { albumArtistId: string };
const handlePlayQueueAdd = usePlayQueueAdd();
const playButtonBehavior = usePlayButtonBehavior();
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 background = useFastAverageColor(detailQuery.data?.imageUrl, !detailQuery.isLoading);
const handlePlay = () => {
handlePlayQueueAdd?.({
byItemType: {
id: [albumArtistId],
type: LibraryItem.ALBUM_ARTIST,
},
playType: playButtonBehavior,
});
};
2023-01-12 18:43:25 -08:00
2023-07-01 19:10:05 -07:00
if (detailQuery.isLoading || !background) return null;
2023-01-12 18:43:25 -08:00
2023-07-01 19:10:05 -07:00
return (
<AnimatedPage key={`album-artist-detail-${albumArtistId}`}>
<NativeScrollArea
ref={scrollAreaRef}
pageHeaderProps={{
backgroundColor: background,
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,
}}
>
<AlbumArtistDetailHeader
ref={headerRef}
background={background}
/>
<AlbumArtistDetailContent background={background} />
2023-07-01 19:10:05 -07:00
</NativeScrollArea>
</AnimatedPage>
);
2023-01-12 18:43:25 -08:00
};
export default AlbumArtistDetailRoute;