feat: series
This commit is contained in:
1 parent
b2eef6c494
commit
1e31520c92
25 files changed
+435
-223
No files matched your search
@@ -10,9 +10,10 @@ export default function Container() {
|
||||
const params = useSearchParams();
|
||||
|
||||
const title = params.get('title');
|
||||
const type = params.get('type');
|
||||
const movieId = params.get('movieId') || undefined;
|
||||
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useSimilar({ movieId });
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useSimilar({ movieId, type: type as ShowType });
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -21,7 +22,7 @@ export default function Container() {
|
||||
Similar: {decodeURIComponent(title || '')}
|
||||
</span>
|
||||
)}
|
||||
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||
<List type={type as ShowType} pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
|
||||
{isFetched && !top?.pages?.[0]?.results?.length && (
|
||||
<div className='h-40 w-full flex items-center justify-center text-xl text-muted-foreground'>
|
||||
Nothing was found
|
||||
|
||||
@@ -8,11 +8,11 @@ import Container from './container';
|
||||
export default async function Similar({ searchParams }: { searchParams: Record<string, string> }) {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const { movieId } = searchParams || {};
|
||||
const { movieId, type } = searchParams || {};
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ['similar', movieId],
|
||||
queryFn: () => similarMovies({ movieId }),
|
||||
queryKey: ['similar', movieId, type],
|
||||
queryFn: () => similarMovies({ movieId, type: type as ShowType }),
|
||||
initialPageParam: '1'
|
||||
});
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
import { similarMovies } from '@/lib/api';
|
||||
|
||||
const useSimilar = ({ movieId }: { movieId?: string }) => {
|
||||
const useSimilar = ({ movieId, type = 'movie' }: { movieId?: string; type?: ShowType }) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['similar', movieId],
|
||||
queryKey: ['similar', movieId, type],
|
||||
enabled: Boolean(movieId),
|
||||
queryFn: ({ pageParam }) => {
|
||||
return similarMovies({ page: pageParam as string, movieId });
|
||||
return similarMovies({ page: pageParam as string, movieId, type });
|
||||
},
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
|
||||
Reference in new issue
Block a user