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
@@ -2,17 +2,18 @@
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
import List from '@/components/List';
|
||||
import NoResults from '@/components/NoResults';
|
||||
|
||||
import useStarring from './useStarring';
|
||||
|
||||
export default function Container() {
|
||||
const Container = () => {
|
||||
const params = useSearchParams();
|
||||
|
||||
const title = params.get('title');
|
||||
const actorId = params.get('actorId') || undefined;
|
||||
const title = params.get('title') as string;
|
||||
const actorId = params.get('actorId') as string;
|
||||
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useStarring({ actorId });
|
||||
const { shows, fetchNextPage, isFetched } = useStarring({ actorId });
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -21,12 +22,10 @@ export default function Container() {
|
||||
Starring: {decodeURIComponent(title || '')}
|
||||
</span>
|
||||
)}
|
||||
<List 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
|
||||
</div>
|
||||
)}
|
||||
<List shows={shows} fetchNextPage={fetchNextPage} />
|
||||
{isFetched && !shows.length && <NoResults />}
|
||||
</>
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Container;
|
||||
@@ -1,6 +1,6 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { topMovies } from '@/lib/api';
|
||||
import { topMovies } from '@/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
@@ -1,24 +1,15 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
import { topMovies } from '@/api';
|
||||
import useInfiniteList from '@/hooks/useInfiniteList';
|
||||
|
||||
import { topMovies } from '@/lib/api';
|
||||
|
||||
const useStarring = ({ actorId }: { actorId?: string }) => {
|
||||
return useInfiniteQuery({
|
||||
const useStarring = ({ actorId }: { actorId?: string }) =>
|
||||
useInfiniteList({
|
||||
queryKey: ['starring', actorId],
|
||||
enabled: Boolean(actorId),
|
||||
queryFn: ({ pageParam }) => {
|
||||
return topMovies({ page: pageParam as string, starring: actorId });
|
||||
},
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
if (page === total_pages) return undefined;
|
||||
|
||||
return `${page + 1}`;
|
||||
},
|
||||
initialPageParam: '1'
|
||||
queryFn: ({ page }) => {
|
||||
return topMovies({ page, starring: actorId });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export default useStarring;
|
||||
Reference in new issue
Block a user