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

84 lines
3.3 KiB
TypeScript
Raw Normal View History

import { NativeScrollArea, Spinner } from '/@/renderer/components';
import { AnimatedPage, LibraryHeaderBar } from '/@/renderer/features/shared';
2022-12-29 18:45:01 -08:00
import { useRef } from 'react';
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
import { useAlbumDetail } from '/@/renderer/features/albums/queries/album-detail-query';
import { useParams } from 'react-router';
import { useFastAverageColor } from '/@/renderer/hooks';
2022-12-29 18:45:01 -08:00
import { AlbumDetailContent } from '/@/renderer/features/albums/components/album-detail-content';
import { AlbumDetailHeader } from '/@/renderer/features/albums/components/album-detail-header';
import { usePlayQueueAdd } from '/@/renderer/features/player';
import { usePlayButtonBehavior } from '/@/renderer/store/settings.store';
2023-01-05 21:59:07 -08:00
import { LibraryItem } from '/@/renderer/api/types';
import { useCurrentServer, useGeneralSettings } from '/@/renderer/store';
2022-12-29 18:45:01 -08:00
const AlbumDetailRoute = () => {
2023-07-01 19:10:05 -07:00
const tableRef = useRef<AgGridReactType | null>(null);
const scrollAreaRef = useRef<HTMLDivElement>(null);
const headerRef = useRef<HTMLDivElement>(null);
const { albumBackground, albumBackgroundBlur } = useGeneralSettings();
2023-07-01 19:10:05 -07:00
const { albumId } = useParams() as { albumId: string };
const server = useCurrentServer();
const detailQuery = useAlbumDetail({ query: { id: albumId }, serverId: server?.id });
const { color: backgroundColor, colorId } = useFastAverageColor({
id: albumId,
src: detailQuery.data?.imageUrl,
srcLoaded: !detailQuery.isLoading,
});
2023-07-01 19:10:05 -07:00
const handlePlayQueueAdd = usePlayQueueAdd();
const playButtonBehavior = usePlayButtonBehavior();
2023-07-01 19:10:05 -07:00
const handlePlay = () => {
handlePlayQueueAdd?.({
byItemType: {
id: [albumId],
type: LibraryItem.ALBUM,
},
playType: playButtonBehavior,
});
};
2022-12-31 17:50:05 -08:00
if (!backgroundColor || colorId !== albumId) {
return <Spinner container />;
}
2022-12-29 18:45:01 -08:00
const backgroundUrl = detailQuery.data?.imageUrl || '';
const background = (albumBackground && `url(${backgroundUrl})`) || backgroundColor;
2023-07-01 19:10:05 -07:00
return (
<AnimatedPage key={`album-detail-${albumId}`}>
<NativeScrollArea
ref={scrollAreaRef}
pageHeaderProps={{
backgroundColor: backgroundColor || undefined,
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,
}}
>
<AlbumDetailHeader
ref={headerRef}
background={{
background,
blur: (albumBackground && albumBackgroundBlur) || 0,
}}
2023-07-01 19:10:05 -07:00
/>
<AlbumDetailContent
background={background}
tableRef={tableRef}
/>
2023-07-01 19:10:05 -07:00
</NativeScrollArea>
</AnimatedPage>
);
2022-12-29 18:45:01 -08:00
};
export default AlbumDetailRoute;