fix: torrent size
This commit is contained in:
1 parent
8d7e2df869
commit
c6d306cb7b
22 files changed
+1638
-300
No files matched your search
@@ -0,0 +1,20 @@
|
||||
'use client';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
|
||||
import usePopular from './usePopular';
|
||||
|
||||
export default function Container() {
|
||||
const { data: top, hasNextPage, 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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { popularMovies } from '@/lib/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
export default async function Popular() {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ['popular'],
|
||||
queryFn: () => popularMovies({}),
|
||||
initialPageParam: '1'
|
||||
});
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
export const revalidate = 3600;
|
||||
@@ -0,0 +1,23 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
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'
|
||||
});
|
||||
};
|
||||
|
||||
export default usePopular;
|
||||
@@ -0,0 +1,32 @@
|
||||
'use client';
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
|
||||
import useSimilar from './useSimilar';
|
||||
|
||||
export default function Container() {
|
||||
const params = useSearchParams();
|
||||
|
||||
const title = params.get('title');
|
||||
const movieId = params.get('movieId') || undefined;
|
||||
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useSimilar({ movieId });
|
||||
|
||||
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'>
|
||||
Similar: {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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { similarMovies } from '@/lib/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
export default async function Similar({ searchParams }: { searchParams: Record<string, string> }) {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const { movieId } = searchParams || {};
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ['similar', movieId],
|
||||
queryFn: () => similarMovies({ movieId }),
|
||||
initialPageParam: '1'
|
||||
});
|
||||
|
||||
return (
|
||||
<HydrationBoundary state={dehydrate(queryClient)}>
|
||||
<Container />
|
||||
</HydrationBoundary>
|
||||
);
|
||||
}
|
||||
|
||||
export const revalidate = 3600;
|
||||
@@ -0,0 +1,24 @@
|
||||
'use client';
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
import { similarMovies } from '@/lib/api';
|
||||
|
||||
const useSimilar = ({ movieId }: { movieId?: string }) => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['similar', movieId],
|
||||
enabled: Boolean(movieId),
|
||||
queryFn: ({ pageParam }) => {
|
||||
return similarMovies({ page: pageParam as string, movieId });
|
||||
},
|
||||
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 useSimilar;
|
||||
@@ -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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -1,27 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import { useSearchParams } from 'next/navigation';
|
||||
|
||||
import List from '@/components/Movie/List';
|
||||
|
||||
import useTop from './useTop';
|
||||
|
||||
export default function Container() {
|
||||
const params = useSearchParams();
|
||||
|
||||
const starring = params.get('starring')!;
|
||||
const similar = params.get('similar')!;
|
||||
const title = params.get('title');
|
||||
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useTop({ starring, similar });
|
||||
const { data: top, hasNextPage, fetchNextPage, isFetched } = useTop();
|
||||
|
||||
return (
|
||||
<>
|
||||
{Boolean(title && (starring || similar)) && (
|
||||
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
|
||||
{starring ? 'Starring' : 'Similar'}: {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'>
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
import { dehydrate, HydrationBoundary } from '@tanstack/react-query';
|
||||
|
||||
import { similarMovies, topMovies } from '@/lib/api';
|
||||
import { topMovies } from '@/lib/api';
|
||||
import getQueryClient from '@/lib/queryClient';
|
||||
|
||||
import Container from './container';
|
||||
|
||||
export default async function Top({ searchParams }: { searchParams: Record<string, string> }) {
|
||||
export default async function Top() {
|
||||
const queryClient = getQueryClient();
|
||||
|
||||
const { starring, similar } = searchParams || {};
|
||||
|
||||
await queryClient.prefetchInfiniteQuery({
|
||||
queryKey: ['top', starring, similar],
|
||||
queryFn: () => (similar ? similarMovies({ movieId: similar }) : topMovies({ starring })),
|
||||
queryKey: ['top'],
|
||||
queryFn: () => topMovies({}),
|
||||
initialPageParam: '1'
|
||||
});
|
||||
|
||||
|
||||
@@ -2,15 +2,13 @@
|
||||
|
||||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
import { similarMovies, topMovies } from '@/lib/api';
|
||||
import { topMovies } from '@/lib/api';
|
||||
|
||||
const useTop = ({ starring, similar }: { starring?: string; similar?: string }) => {
|
||||
const useTop = () => {
|
||||
return useInfiniteQuery({
|
||||
queryKey: ['top', starring, similar],
|
||||
queryKey: ['top'],
|
||||
queryFn: ({ pageParam }) => {
|
||||
return similar
|
||||
? similarMovies({ page: pageParam as string, movieId: similar })
|
||||
: topMovies({ page: pageParam as string, starring: starring! });
|
||||
return topMovies({ page: pageParam as string });
|
||||
},
|
||||
getNextPageParam(lastPage) {
|
||||
const { page, total_pages } = lastPage as { page: number; total_pages: number };
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import '@/styles/index.css';
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: 'Movie advisor',
|
||||
description: 'It will help you find a movie for evening'
|
||||
description: 'It is going to help you find a movie for evening'
|
||||
};
|
||||
|
||||
export const viewport: Viewport = {
|
||||
|
||||
Reference in new issue
Block a user