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;
|
||||
Reference in new issue
Block a user