refactor: clean code and remove unnecessary dependencies
This commit is contained in:
1 parent
eceae6fec7
commit
ebf599eed6
92 files changed
+1152
-2842
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { FC } from 'react';
|
||||
|
||||
import { showPreviewModal } from '@/components/Preview';
|
||||
import Card from '@/components/Show';
|
||||
|
||||
interface Props {
|
||||
shows: Show[];
|
||||
}
|
||||
|
||||
const Marquee: FC<Props> = ({ shows }) => (
|
||||
<ul className='flex overflow-auto gap-2 rounded-lg snap-mandatory snap-x no-scrollbar opacity-0 animate-fade-aside-slide-in'>
|
||||
{shows.map((show) => (
|
||||
<li key={show.id} className='snap-start'>
|
||||
<Card className='!h-[350px] !w-[230px] text-sm' show={show} onClick={() => showPreviewModal({ show })} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
||||
|
||||
export default Marquee;
|
||||
@@ -0,0 +1,14 @@
|
||||
export const tabs = [
|
||||
{
|
||||
title: 'Trending',
|
||||
type: 'trending'
|
||||
},
|
||||
{
|
||||
title: 'Streaming',
|
||||
type: 'streaming'
|
||||
},
|
||||
{
|
||||
title: 'In theaters',
|
||||
type: 'theater'
|
||||
}
|
||||
];
|
||||
@@ -0,0 +1,31 @@
|
||||
'use client';
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
|
||||
import Nav from '@/components/ui/nav';
|
||||
|
||||
import Marquee from './components/Marquee';
|
||||
import { tabs } from './constants';
|
||||
import useTrending from './useTrending';
|
||||
|
||||
const Trending: FC = () => {
|
||||
const [active, setActive] = useState(tabs[0]);
|
||||
const isMobile = typeof window === 'undefined' ? true : matchMedia('(max-width: 600px)').matches;
|
||||
|
||||
const { data: trending, isFetched } = useTrending({ type: 'trending', enabled: !isMobile });
|
||||
const { data: streaming } = useTrending({ type: 'streaming', enabled: !isMobile });
|
||||
const { data: theater } = useTrending({ type: 'theater', enabled: !isMobile });
|
||||
|
||||
const shows = { trending, streaming, theater }[active.type] || [];
|
||||
|
||||
return (
|
||||
isFetched && (
|
||||
<div>
|
||||
<Nav tabs={tabs} active={active} onChange={(active) => setActive(active)} className='mb-3' />
|
||||
<Marquee key={active.type} shows={shows} />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export default Trending;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { popularByType, trendingMovies } from '@/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