feat: Initialize project

This commit is contained in:
ner committed 2023-08-05 12:28:04 +03:00
1 parent eccc32337f
commit 3c1050898e
65 files changed
+5661 -596

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
import client from '@/network';
const API = {
top({ page }: { page: string }): Promise<MovieDBResponse> {
return client.get('/discover', {
params: {
page,
sort_by: 'vote_average.desc',
'vote_count.gte': 300,
'vote_average.lte': 10,
'vote_average.gte': 0
}
});
}
};
export default API;
+11
View File
@@ -0,0 +1,11 @@
'use client';
import List from '@/components/Movie/List';
import useTop from './useTop';
export default function Container() {
const { data: top, hasNextPage, fetchNextPage } = useTop();
return <List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />;
}
+5
View File
@@ -0,0 +1,5 @@
import Container from './container';
export default function Top() {
return <Container />;
}
+32
View File
@@ -0,0 +1,32 @@
'use client';
import { useInfiniteQuery } from '@tanstack/react-query';
import { useSearchParams } from 'next/navigation';
import API from './api';
const useTop = () => {
const page = useSearchParams().get('page');
return useInfiniteQuery({
queryKey: ['top'],
queryFn: ({ pageParam: page }) => API.top({ page }),
suspense: true,
getNextPageParam({ page, total_pages }) {
if (page === total_pages) return undefined;
if (typeof window !== 'undefined') {
const url = new URL(location.href);
url.searchParams.set('page', page.toString());
window.history.pushState(null, '', url.href);
}
return `${page + 1}`;
},
defaultPageParam: page || '1'
});
};
export default useTop;