refactor: clean code and remove unnecessary dependencies

This commit is contained in:
ner committed 2024-09-30 18:54:13 +03:00
1 parent eceae6fec7
commit ebf599eed6
92 files changed
+1152 -2842

No files matched your search

+11 -17
View File
@@ -1,24 +1,18 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { similarShows } from '@/api';
import useInfiniteList from '@/hooks/useInfiniteList';
import { similarMovies } from '@/lib/api';
interface Props {
showId: string;
showType: Show['type'];
}
const useSimilar = ({ movieId, type = 'movie' }: { movieId?: string; type?: ShowType }) => {
return useInfiniteQuery({
queryKey: ['similar', movieId, type],
enabled: Boolean(movieId),
queryFn: ({ pageParam }) => {
return similarMovies({ page: pageParam as string, movieId, type });
},
getNextPageParam(lastPage) {
const { page, total_pages } = lastPage as { page: number; total_pages: number };
if (page === total_pages) return undefined;
return `${page + 1}`;
},
initialPageParam: '1'
const useSimilar = ({ showId, showType = 'movie' }: Props) =>
useInfiniteList({
enabled: Boolean(showId),
queryKey: ['similar', showId, showType],
queryFn: ({ page }) => similarShows({ page, showId, showType })
});
};
export default useSimilar;