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

+10 -14
View File
@@ -1,20 +1,16 @@
'use client';
import List from '@/components/Movie/List';
import List from '@/components/List';
import NoResults from '@/components/NoResults';
import usePopular from './usePopular';
export default function Container() {
const { data: top, hasNextPage, fetchNextPage, isFetched } = usePopular();
const Container = () => {
const { shows, fetchNextPage, isFetched } = usePopular();
return (
<>
<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>
)}
</>
);
}
if (isFetched && !shows.length) return <NoResults />;
return <List shows={shows} fetchNextPage={fetchNextPage} />;
};
export default Container;
+5 -5
View File
@@ -1,7 +1,7 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { Metadata } from 'next';
import { popularMovies } from '@/lib/api';
import { popularMovies } from '@/api';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
@@ -12,9 +12,7 @@ export const metadata: Metadata = {
'Check out the most popular movies right now on Movie Advisor. See what’s trending and don’t miss out on the latest hits.'
};
export const revalidate = 3600;
export default async function Popular() {
const Popular = async () => {
const queryClient = getQueryClient();
await queryClient.prefetchInfiniteQuery({
@@ -28,4 +26,6 @@ export default async function Popular() {
<Container />
</HydrationBoundary>
);
}
};
export default Popular;
+3 -18
View File
@@ -1,23 +1,8 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { popularMovies } from '@/api';
import useInfiniteList from '@/hooks/useInfiniteList';
import { popularMovies } from '@/lib/api';
const usePopular = () => {
return useInfiniteQuery({
queryKey: ['popular'],
queryFn: ({ pageParam }) => {
return popularMovies({ page: pageParam as string });
},
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 usePopular = () => useInfiniteList({ queryKey: ['popular'], queryFn: popularMovies });
export default usePopular;