2023-05-17 17:12:23 -07:00
|
|
|
import { useMemo, useRef } from 'react';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { Box, Stack } from '@mantine/core';
|
2023-01-12 12:45:44 -08:00
|
|
|
import { AlbumListSort, LibraryItem, ServerType, SortOrder } from '/@/renderer/api/types';
|
2023-05-17 17:12:23 -07:00
|
|
|
import { FeatureCarousel, NativeScrollArea } 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 { useContainerQuery } from '/@/renderer/hooks';
|
|
|
|
|
import { AppRoute } from '/@/renderer/router/routes';
|
2023-05-17 17:12:23 -07:00
|
|
|
import { useCurrentServer, useWindowSettings } from '/@/renderer/store';
|
|
|
|
|
import { SwiperGridCarousel } from '/@/renderer/components/grid-carousel';
|
|
|
|
|
import { Platform } from '/@/renderer/types';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const HomeRoute = () => {
|
2023-01-02 18:20:45 -08:00
|
|
|
const scrollAreaRef = useRef<HTMLDivElement>(null);
|
2022-12-29 18:46:09 -08:00
|
|
|
const server = useCurrentServer();
|
2022-12-19 15:59:14 -08:00
|
|
|
const cq = useContainerQuery();
|
2023-05-17 17:12:23 -07:00
|
|
|
const itemsPerPage = 25;
|
|
|
|
|
const { windowBarStyle } = useWindowSettings();
|
2022-12-19 15:59:14 -08:00
|
|
|
|
2023-04-30 22:01:52 -07:00
|
|
|
const feature = useAlbumList({
|
|
|
|
|
options: {
|
|
|
|
|
cacheTime: 1000 * 60,
|
|
|
|
|
staleTime: 1000 * 60,
|
|
|
|
|
},
|
|
|
|
|
query: {
|
2022-12-24 21:15:56 -08:00
|
|
|
limit: 20,
|
|
|
|
|
sortBy: AlbumListSort.RANDOM,
|
|
|
|
|
sortOrder: SortOrder.DESC,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const featureItemsWithImage = useMemo(() => {
|
|
|
|
|
return feature.data?.items?.filter((item) => item.imageUrl) ?? [];
|
|
|
|
|
}, [feature.data?.items]);
|
|
|
|
|
|
2023-04-30 22:01:52 -07:00
|
|
|
const random = useAlbumList({
|
|
|
|
|
options: {
|
2023-05-17 17:12:23 -07:00
|
|
|
staleTime: 1000 * 60 * 5,
|
2023-04-30 22:01:52 -07:00
|
|
|
},
|
|
|
|
|
query: {
|
2022-12-19 15:59:14 -08:00
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RANDOM,
|
|
|
|
|
sortOrder: SortOrder.ASC,
|
2023-05-17 17:12:23 -07:00
|
|
|
startIndex: 0,
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const recentlyPlayed = useRecentlyPlayed({
|
|
|
|
|
options: {
|
|
|
|
|
staleTime: 0,
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
query: {
|
2022-12-19 15:59:14 -08:00
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RECENTLY_PLAYED,
|
2022-12-24 21:09:46 -08:00
|
|
|
sortOrder: SortOrder.DESC,
|
2023-05-17 17:12:23 -07:00
|
|
|
startIndex: 0,
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const recentlyAdded = useAlbumList({
|
|
|
|
|
query: {
|
2022-12-19 15:59:14 -08:00
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.RECENTLY_ADDED,
|
2022-12-24 21:09:46 -08:00
|
|
|
sortOrder: SortOrder.DESC,
|
2023-05-17 17:12:23 -07:00
|
|
|
startIndex: 0,
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mostPlayed = useAlbumList({
|
|
|
|
|
options: {
|
2023-05-17 17:12:23 -07:00
|
|
|
staleTime: 1000 * 60 * 5,
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
query: {
|
2022-12-19 15:59:14 -08:00
|
|
|
limit: itemsPerPage,
|
|
|
|
|
sortBy: AlbumListSort.PLAY_COUNT,
|
|
|
|
|
sortOrder: SortOrder.DESC,
|
2023-05-17 17:12:23 -07:00
|
|
|
startIndex: 0,
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const carousels = [
|
|
|
|
|
{
|
|
|
|
|
data: random?.data?.items,
|
2023-05-17 17:12:23 -07:00
|
|
|
loading: random?.isLoading,
|
|
|
|
|
title: 'Explore from your library',
|
2022-12-19 15:59:14 -08:00
|
|
|
uniqueId: 'random',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: recentlyPlayed?.data?.items,
|
2023-05-17 17:12:23 -07:00
|
|
|
loading: recentlyPlayed?.isLoading,
|
2022-12-19 15:59:14 -08:00
|
|
|
pagination: {
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
},
|
2023-05-17 17:12:23 -07:00
|
|
|
title: 'Recently played',
|
2022-12-19 15:59:14 -08:00
|
|
|
uniqueId: 'recentlyPlayed',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: recentlyAdded?.data?.items,
|
2023-05-17 17:12:23 -07:00
|
|
|
loading: recentlyAdded?.isLoading,
|
2022-12-19 15:59:14 -08:00
|
|
|
pagination: {
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
},
|
2023-05-17 17:12:23 -07:00
|
|
|
title: 'Newly added releases',
|
2022-12-19 15:59:14 -08:00
|
|
|
uniqueId: 'recentlyAdded',
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
data: mostPlayed?.data?.items,
|
2023-05-17 17:12:23 -07:00
|
|
|
loading: mostPlayed?.isLoading,
|
2022-12-19 15:59:14 -08:00
|
|
|
pagination: {
|
|
|
|
|
itemsPerPage,
|
|
|
|
|
},
|
2023-05-17 17:12:23 -07:00
|
|
|
title: 'Most played',
|
2022-12-19 15:59:14 -08:00
|
|
|
uniqueId: 'mostPlayed',
|
|
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<AnimatedPage>
|
2023-01-02 18:20:45 -08:00
|
|
|
<NativeScrollArea
|
|
|
|
|
ref={scrollAreaRef}
|
|
|
|
|
pageHeaderProps={{
|
|
|
|
|
backgroundColor: 'var(--titlebar-bg)',
|
|
|
|
|
children: (
|
|
|
|
|
<LibraryHeaderBar>
|
|
|
|
|
<LibraryHeaderBar.Title>Home</LibraryHeaderBar.Title>
|
|
|
|
|
</LibraryHeaderBar>
|
|
|
|
|
),
|
|
|
|
|
offset: ['0px', '200px'],
|
|
|
|
|
}}
|
|
|
|
|
>
|
2022-12-19 15:59:14 -08:00
|
|
|
<Box
|
2023-01-02 18:20:45 -08:00
|
|
|
ref={cq.ref}
|
2023-05-17 17:12:23 -07:00
|
|
|
pt={windowBarStyle === Platform.WEB ? '5rem' : '3rem'}
|
2023-01-02 18:20:45 -08:00
|
|
|
px="2rem"
|
2022-12-19 15:59:14 -08:00
|
|
|
>
|
2023-01-02 18:20:45 -08:00
|
|
|
<Stack spacing={35}>
|
|
|
|
|
<FeatureCarousel data={featureItemsWithImage} />
|
|
|
|
|
{carousels
|
|
|
|
|
.filter((carousel) => {
|
|
|
|
|
if (
|
|
|
|
|
server?.type === ServerType.JELLYFIN &&
|
|
|
|
|
carousel.uniqueId === 'recentlyPlayed'
|
|
|
|
|
) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
2022-12-29 18:46:09 -08:00
|
|
|
|
2023-01-02 18:20:45 -08:00
|
|
|
return carousel;
|
|
|
|
|
})
|
2023-05-17 17:12:23 -07:00
|
|
|
.map((carousel) => (
|
|
|
|
|
<SwiperGridCarousel
|
|
|
|
|
key={`carousel-${carousel.uniqueId}`}
|
2023-01-02 18:20:45 -08:00
|
|
|
cardRows={[
|
|
|
|
|
{
|
|
|
|
|
property: 'name',
|
|
|
|
|
route: {
|
|
|
|
|
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
|
|
|
|
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-01-02 18:20:45 -08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
arrayProperty: 'name',
|
|
|
|
|
property: 'albumArtists',
|
|
|
|
|
route: {
|
2023-01-12 12:45:44 -08:00
|
|
|
route: AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL,
|
2023-01-02 18:20:45 -08:00
|
|
|
slugs: [{ idProperty: 'id', slugProperty: 'albumArtistId' }],
|
2022-12-19 15:59:14 -08:00
|
|
|
},
|
2023-01-02 18:20:45 -08:00
|
|
|
},
|
|
|
|
|
]}
|
|
|
|
|
data={carousel.data}
|
2023-05-17 17:12:23 -07:00
|
|
|
isLoading={carousel.loading}
|
2023-01-12 12:45:44 -08:00
|
|
|
itemType={LibraryItem.ALBUM}
|
2023-05-17 17:12:23 -07:00
|
|
|
route={{
|
|
|
|
|
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
|
|
|
|
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
|
|
|
|
}}
|
|
|
|
|
title={{ label: carousel.title }}
|
2023-01-02 18:20:45 -08:00
|
|
|
uniqueId={carousel.uniqueId}
|
2023-05-17 17:12:23 -07:00
|
|
|
/>
|
2023-01-02 18:20:45 -08:00
|
|
|
))}
|
|
|
|
|
</Stack>
|
2022-12-19 15:59:14 -08:00
|
|
|
</Box>
|
2023-01-02 18:20:45 -08:00
|
|
|
</NativeScrollArea>
|
2022-12-19 15:59:14 -08:00
|
|
|
</AnimatedPage>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default HomeRoute;
|