2023-05-17 17:12:23 -07:00
|
|
|
import { useMemo, useRef } from 'react';
|
2023-08-08 09:26:21 -07:00
|
|
|
import { ActionIcon, Group, Stack } from '@mantine/core';
|
2023-01-12 12:45:44 -08:00
|
|
|
import { AlbumListSort, LibraryItem, ServerType, SortOrder } from '/@/renderer/api/types';
|
2023-08-08 09:26:21 -07:00
|
|
|
import { FeatureCarousel, NativeScrollArea, Spinner, TextTitle } from '/@/renderer/components';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { useAlbumList } from '/@/renderer/features/albums';
|
|
|
|
|
import { useRecentlyPlayed } from '/@/renderer/features/home/queries/recently-played-query';
|
2023-01-02 18:20:45 -08:00
|
|
|
import { AnimatedPage, LibraryHeaderBar } from '/@/renderer/features/shared';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2023-05-17 17:12:23 -07:00
|
|
|
import { useCurrentServer, useWindowSettings } from '/@/renderer/store';
|
2023-07-21 18:03:19 -07:00
|
|
|
import { MemoizedSwiperGridCarousel } from '/@/renderer/components/grid-carousel';
|
2023-05-17 17:12:23 -07:00
|
|
|
import { Platform } from '/@/renderer/types';
|
2023-08-08 09:26:21 -07:00
|
|
|
import { useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
|
|
|
|
import { RiRefreshLine } from 'react-icons/ri';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const HomeRoute = () => {
|
2023-08-08 09:26:21 -07:00
|
|
|
const queryClient = useQueryClient();
|
2023-07-01 19:10:05 -07:00
|
|
|
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const server = useCurrentServer();
|
|
|
|
|
const itemsPerPage = 15;
|
|
|
|
|
const { windowBarStyle } = useWindowSettings();
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const feature = useAlbumList({
|
|
|
|
|
options: {
|
|
|
|
|
cacheTime: 1000 * 60,
|
|
|
|
|
staleTime: 1000 * 60,
|
|
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
limit: 20,
|
|
|
|
|
sortBy: AlbumListSort.RANDOM,
|
|
|
|
|
sortOrder: SortOrder.DESC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const featureItemsWithImage = useMemo(() => {
|
|
|
|
|
return feature.data?.items?.filter((item) => item.imageUrl) ?? [];
|
|
|
|
|
}, [feature.data?.items]);
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const random = useAlbumList({
|
|
|
|
|
options: {
|
|
|
|
|
staleTime: 1000 * 60 * 5,
|
|
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RANDOM,
|
|
|
|
|
sortOrder: SortOrder.ASC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2023-04-30 22:01:52 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const recentlyPlayed = useRecentlyPlayed({
|
|
|
|
|
options: {
|
|
|
|
|
staleTime: 0,
|
|
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RECENTLY_PLAYED,
|
|
|
|
|
sortOrder: SortOrder.DESC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2023-04-30 22:01:52 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const recentlyAdded = useAlbumList({
|
|
|
|
|
options: {
|
2023-08-08 09:26:21 -07:00
|
|
|
staleTime: 1000 * 60 * 5,
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RECENTLY_ADDED,
|
|
|
|
|
sortOrder: SortOrder.DESC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2023-04-30 22:01:52 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const mostPlayed = useAlbumList({
|
|
|
|
|
options: {
|
2023-08-08 09:26:21 -07:00
|
|
|
staleTime: 1000 * 60 * 5,
|
2023-07-01 19:10:05 -07:00
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.PLAY_COUNT,
|
|
|
|
|
sortOrder: SortOrder.DESC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const isLoading =
|
2023-08-08 09:26:21 -07:00
|
|
|
random.isLoading ||
|
|
|
|
|
recentlyPlayed.isLoading ||
|
|
|
|
|
recentlyAdded.isLoading ||
|
|
|
|
|
mostPlayed.isLoading;
|
2023-06-01 20:08:43 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
if (isLoading) {
|
|
|
|
|
return <Spinner container />;
|
|
|
|
|
}
|
2023-06-01 20:08:43 -07:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const carousels = [
|
|
|
|
|
{
|
|
|
|
|
data: random?.data?.items,
|
2023-08-08 09:26:21 -07:00
|
|
|
title: (
|
|
|
|
|
<Group>
|
|
|
|
|
<TextTitle
|
|
|
|
|
order={2}
|
|
|
|
|
weight={700}
|
|
|
|
|
>
|
|
|
|
|
Explore from your library
|
|
|
|
|
</TextTitle>
|
|
|
|
|
|
|
|
|
|
<ActionIcon
|
|
|
|
|
onClick={() =>
|
|
|
|
|
queryClient.invalidateQueries({
|
|
|
|
|
exact: false,
|
|
|
|
|
queryKey: queryKeys.albums.list(server?.id, {
|
|
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RANDOM,
|
|
|
|
|
sortOrder: SortOrder.ASC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
}),
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
<RiRefreshLine />
|
|
|
|
|
</ActionIcon>
|
|
|
|
|
</Group>
|
|
|
|
|
),
|
2023-07-01 19:10:05 -07:00
|
|
|
uniqueId: 'random',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: recentlyPlayed?.data?.items,
|
|
|
|
|
pagination: {
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
},
|
|
|
|
|
title: 'Recently played',
|
|
|
|
|
uniqueId: 'recentlyPlayed',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: recentlyAdded?.data?.items,
|
|
|
|
|
pagination: {
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
},
|
|
|
|
|
title: 'Newly added releases',
|
|
|
|
|
uniqueId: 'recentlyAdded',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: mostPlayed?.data?.items,
|
|
|
|
|
pagination: {
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
},
|
|
|
|
|
title: 'Most played',
|
|
|
|
|
uniqueId: 'mostPlayed',
|
|
|
|
|
},
|
|
|
|
|
];
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<AnimatedPage>
|
|
|
|
|
<NativeScrollArea
|
|
|
|
|
ref={scrollAreaRef}
|
|
|
|
|
pageHeaderProps={{
|
|
|
|
|
backgroundColor: 'var(--titlebar-bg)',
|
|
|
|
|
children: (
|
|
|
|
|
<LibraryHeaderBar>
|
|
|
|
|
<LibraryHeaderBar.Title>Home</LibraryHeaderBar.Title>
|
|
|
|
|
</LibraryHeaderBar>
|
|
|
|
|
),
|
2023-07-21 05:20:40 -07:00
|
|
|
offset: 200,
|
2023-06-01 20:08:43 -07:00
|
|
|
}}
|
2023-07-01 19:10:05 -07:00
|
|
|
>
|
|
|
|
|
<Stack
|
|
|
|
|
mb="5rem"
|
|
|
|
|
pt={windowBarStyle === Platform.WEB ? '5rem' : '3rem'}
|
|
|
|
|
px="2rem"
|
|
|
|
|
spacing="lg"
|
|
|
|
|
>
|
|
|
|
|
<FeatureCarousel data={featureItemsWithImage} />
|
|
|
|
|
{carousels
|
|
|
|
|
.filter((carousel) => {
|
|
|
|
|
if (
|
|
|
|
|
server?.type === ServerType.JELLYFIN &&
|
|
|
|
|
carousel.uniqueId === 'recentlyPlayed'
|
|
|
|
|
) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return carousel;
|
|
|
|
|
})
|
|
|
|
|
.map((carousel) => (
|
2023-07-21 18:03:19 -07:00
|
|
|
<MemoizedSwiperGridCarousel
|
2023-07-01 19:10:05 -07:00
|
|
|
key={`carousel-${carousel.uniqueId}`}
|
|
|
|
|
cardRows={[
|
|
|
|
|
{
|
|
|
|
|
property: 'name',
|
|
|
|
|
route: {
|
|
|
|
|
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
|
|
|
|
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
arrayProperty: 'name',
|
|
|
|
|
property: 'albumArtists',
|
|
|
|
|
route: {
|
|
|
|
|
route: AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL,
|
|
|
|
|
slugs: [
|
2023-08-08 09:26:21 -07:00
|
|
|
{
|
|
|
|
|
idProperty: 'id',
|
|
|
|
|
slugProperty: 'albumArtistId',
|
|
|
|
|
},
|
2023-07-01 19:10:05 -07:00
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
data={carousel.data}
|
|
|
|
|
itemType={LibraryItem.ALBUM}
|
|
|
|
|
route={{
|
|
|
|
|
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
|
|
|
|
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
|
|
|
|
}}
|
|
|
|
|
title={{ label: carousel.title }}
|
|
|
|
|
uniqueId={carousel.uniqueId}
|
|
|
|
|
/>
|
|
|
|
|
))}
|
|
|
|
|
</Stack>
|
|
|
|
|
</NativeScrollArea>
|
|
|
|
|
</AnimatedPage>
|
|
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default HomeRoute;
|