fix: torrent size

This commit is contained in:
ner committed 2024-03-19 20:15:42 +02:00
1 parent 8d7e2df869
commit c6d306cb7b
22 files changed
+1638 -300

No files matched your search

+32
View File
@@ -0,0 +1,32 @@
'use client';
import { useSearchParams } from 'next/navigation';
import List from '@/components/Movie/List';
import useStarring from './useStarring';
export default function Container() {
const params = useSearchParams();
const title = params.get('title');
const actorId = params.get('actorId') || undefined;
const { data: top, hasNextPage, fetchNextPage, isFetched } = useStarring({ actorId });
return (
<>
{Boolean(title) && (
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
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>
)}
</>
);
}
+26
View File
@@ -0,0 +1,26 @@
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
import { topMovies } from '@/lib/api';
import getQueryClient from '@/lib/queryClient';
import Container from './container';
export default async function Starring({ searchParams }: { searchParams: Record<string, string> }) {
const queryClient = getQueryClient();
const { actorId } = searchParams || {};
await queryClient.prefetchInfiniteQuery({
queryKey: ['starring', actorId],
queryFn: () => topMovies({ starring: actorId }),
initialPageParam: '1'
});
return (
<HydrationBoundary state={dehydrate(queryClient)}>
<Container />
</HydrationBoundary>
);
}
export const revalidate = 3600;
+24
View File
@@ -0,0 +1,24 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { topMovies } from '@/lib/api';
const useStarring = ({ actorId }: { actorId?: string }) => {
return useInfiniteQuery({
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'
});
};
export default useStarring;