feat: trending blocks on main page
This commit is contained in:
1 parent
8263a4abd4
commit
aff28018f6
8 files changed
+122
-19
No files matched your search
@@ -0,0 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import Marquee from '@/components/Marquee';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { FC } from 'react';
|
||||
import useTrending from './useTrending';
|
||||
|
||||
const Trending: FC<{ label: string; type: 'trending' | 'streaming' | 'theater' | 'rent' }> = ({ label, type }) => {
|
||||
const isMobile = typeof window === 'undefined' ? true : matchMedia('(max-width: 600px)').matches;
|
||||
const { data: movies, isFetched } = useTrending({ type, enabled: !isMobile });
|
||||
|
||||
return (
|
||||
isFetched && (
|
||||
<>
|
||||
<Badge className='mb-2 font-normal'>{label}</Badge>
|
||||
<Marquee movies={movies || []} />
|
||||
</>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export default Trending;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { popularByType, trendingMovies } from '@/lib/api';
|
||||
|
||||
const useTrending = ({ type, enabled }: { enabled?: boolean; type: 'trending' | 'streaming' | 'theater' | 'rent' }) => {
|
||||
return useQuery({
|
||||
enabled,
|
||||
queryKey: ['trending', type],
|
||||
queryFn: () => (type === 'trending' ? trendingMovies() : popularByType({ type }))
|
||||
});
|
||||
};
|
||||
|
||||
export default useTrending;
|
||||
@@ -4,18 +4,41 @@ import Preview from '@/components/Movie/Preview';
|
||||
|
||||
import Carousel from './components/Carousel';
|
||||
import useRandomMovie from './useRandomMovie';
|
||||
import Trending from './components/Trending';
|
||||
|
||||
export default function Container() {
|
||||
const Random = () => {
|
||||
const { movies, movie, index, onIndexChange, fetchNextPage } = useRandomMovie();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Preview
|
||||
movie={movie}
|
||||
className='bg-background rounded-md'
|
||||
card={<Carousel index={index} movies={movies} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||
/>
|
||||
<div className='w-full h-2' />
|
||||
</>
|
||||
<Preview
|
||||
movie={movie}
|
||||
className='bg-background rounded-md'
|
||||
card={<Carousel index={index} movies={movies} onIndexChange={onIndexChange} onEndReached={fetchNextPage} />}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default function Container() {
|
||||
return (
|
||||
<div className='flex flex-col flex-1'>
|
||||
<div className='xs:mb-4'>
|
||||
<Random />
|
||||
<div className='w-full h-2' />
|
||||
</div>
|
||||
|
||||
<div className='xs:flex hidden flex-1 w-full h-full overflow-auto snap-mandatory snap-y relative rounded-lg no-scrollbar'>
|
||||
<div className='absolute left-0 top-0 w-full'>
|
||||
<div className='snap-center'>
|
||||
<Trending label='Trending' type='trending' />
|
||||
</div>
|
||||
<div className='mt-6 snap-center'>
|
||||
<Trending label='Streaming' type='streaming' />
|
||||
</div>
|
||||
<div className='mt-6 mb-6 snap-center'>
|
||||
<Trending label='In theaters' type='theater' />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user