feat: movie groups on main page

This commit is contained in:
ner committed 2024-09-13 15:27:28 +03:00
1 parent 57ebf9e669
commit e3b9ed78f2
5 files changed
+110 -63

No files matched your search

+29 -8
View File
@@ -1,22 +1,43 @@
'use client';
import { FC } from 'react';
import { FC, useState } from 'react';
import Marquee from '@/components/Marquee';
import { Badge } from '@/components/ui/badge';
import Nav from '@/components/ui/nav';
import useTrending from './useTrending';
const Trending: FC<{ label: string; type: 'trending' | 'streaming' | 'theater' | 'rent' }> = ({ label, type }) => {
const tabs = [
{
title: 'Trending',
type: 'trending'
},
{
title: 'Streaming',
type: 'streaming'
},
{
title: 'In theaters',
type: 'theater'
}
];
const Trending: FC = () => {
const [active, setActive] = useState(tabs[0]);
const isMobile = typeof window === 'undefined' ? true : matchMedia('(max-width: 600px)').matches;
const { data: movies, isFetched } = useTrending({ type, enabled: !isMobile });
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 movies = { trending, streaming, theater }[active.type] || [];
return (
isFetched && (
<>
<Badge className='mb-2 font-normal'>{label}</Badge>
<Marquee movies={movies || []} />
</>
<div>
<Nav tabs={tabs} active={active} onChange={(active) => setActive(active)} className='mb-3' />
<Marquee key={active.type} movies={movies} />
</div>
)
);
};
+3 -12
View File
@@ -26,18 +26,9 @@ export default function Container() {
<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 className='xs:block hidden w-full rounded-lg'>
<Trending />
<div className='w-full h-2' />
</div>
</div>
);