feat: show page
This commit is contained in:
1 parent
abe1c795a1
commit
183c7231a1
26 files changed
+210
-176
No files matched your search
@@ -10,5 +10,13 @@ export const tabs = [
|
||||
{
|
||||
title: 'In theaters',
|
||||
type: 'theater'
|
||||
},
|
||||
{
|
||||
title: 'Similar',
|
||||
type: 'similar'
|
||||
},
|
||||
{
|
||||
title: 'Recommendations',
|
||||
type: 'recommendations'
|
||||
}
|
||||
];
|
||||
@@ -2,26 +2,47 @@
|
||||
|
||||
import { FC, useState } from 'react';
|
||||
|
||||
import useSimilar from '@/components/Trending/useSimilar';
|
||||
import Nav from '@/components/ui/nav';
|
||||
|
||||
import Gallery from './components/Gallery';
|
||||
import { tabs } from './constants';
|
||||
import { tabs as initialTabs } from './constants';
|
||||
import useTrending from './useTrending';
|
||||
|
||||
const Trending: FC = () => {
|
||||
interface Props {
|
||||
showType: Show['type'];
|
||||
showId: Show['id'];
|
||||
preview?: boolean;
|
||||
}
|
||||
|
||||
const Trending: FC<Props> = ({ showId, showType, preview }) => {
|
||||
const tabs = preview ? initialTabs.filter(({ type }) => ['similar', 'recommendations'].includes(type)) : initialTabs;
|
||||
|
||||
const [active, setActive] = useState(tabs[0]);
|
||||
|
||||
const { data: streaming, isFetched } = useTrending({ type: 'streaming' });
|
||||
const { data: trending } = useTrending({ type: 'trending' });
|
||||
const { data: theater } = useTrending({ type: 'theater' });
|
||||
const streaming = useTrending({ type: 'streaming', enabled: !preview });
|
||||
const trending = useTrending({ type: 'trending', enabled: active.type === 'trending' });
|
||||
const theater = useTrending({ type: 'theater', enabled: active.type === 'theater' });
|
||||
const similar = useSimilar({
|
||||
showId,
|
||||
showType,
|
||||
type: 'similar',
|
||||
enabled: active.type === 'similar'
|
||||
});
|
||||
const recommendations = useSimilar({
|
||||
showId,
|
||||
showType,
|
||||
type: 'recommendations',
|
||||
enabled: active.type === 'recommendations'
|
||||
});
|
||||
|
||||
const shows = { trending, streaming, theater }[active.type] || [];
|
||||
const tab = { trending, streaming, theater, similar, recommendations }[active.type]!;
|
||||
|
||||
return (
|
||||
isFetched && (
|
||||
(streaming.isFetched || similar.isFetched) && (
|
||||
<div className='hidden md:block'>
|
||||
<Nav tabs={tabs} active={active} onChange={(active) => setActive(active)} className='mb-3' />
|
||||
<Gallery key={active.type} shows={shows} />
|
||||
{!tab.isPending && <Gallery key={active.type} shows={tab.data || []} />}
|
||||
</div>
|
||||
)
|
||||
);
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
'use client';
|
||||
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import similarQuery from '@/data/queries/similar';
|
||||
|
||||
interface Props {
|
||||
showId: Show['id'];
|
||||
showType: Show['type'];
|
||||
type?: 'similar' | 'recommendations';
|
||||
enabled: boolean;
|
||||
}
|
||||
|
||||
const useSimilar = ({ showId, showType = 'movie', type = 'similar', enabled }: Props) =>
|
||||
useQuery({ ...similarQuery({ showId, showType, type }), enabled });
|
||||
|
||||
export default useSimilar;
|
||||
@@ -2,6 +2,6 @@ import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import trendingQuery, { TrendingQueryProps } from '@/data/queries/trending';
|
||||
|
||||
const useTrending = ({ type }: TrendingQueryProps) => useQuery(trendingQuery({ type }));
|
||||
const useTrending = ({ type, enabled }: TrendingQueryProps) => useQuery(trendingQuery({ type, enabled }));
|
||||
|
||||
export default useTrending;
|
||||
Reference in new issue
Block a user