feat: added favorites page

This commit is contained in:
ner committed 2023-08-09 18:43:48 +03:00
1 parent 0cb860d0a0
commit 89e76f5df6
27 files changed
+412 -116

No files matched your search

+10 -1
View File
@@ -1,16 +1,25 @@
import client from '@/network';
const API = {
top({ page }: { page: string }): Promise<MovieDBResponse> {
top({ page, starring }: { page: string; starring: string | null }): Promise<MovieDBResponse> {
return client.get('/discover', {
params: {
page,
with_cast: starring,
with_people: starring,
sort_by: 'vote_average.desc',
'vote_count.gte': 300,
'vote_average.lte': 10,
'vote_average.gte': 0
}
});
},
person({ id }: { id: string }): Promise<Person> {
return client.get('/person', {
params: {
id
}
});
}
};
+16 -2
View File
@@ -1,11 +1,25 @@
'use client';
import { useSearchParams } from 'next/navigation';
import usePerson from '@/app/(site)/top/usePerson';
import List from '@/components/Movie/List';
import useTop from './useTop';
export default function Container() {
const { data: top, hasNextPage, fetchNextPage } = useTop();
const starring = useSearchParams().get('starring');
const { data: person } = usePerson({ id: starring });
const { data: top, hasNextPage, fetchNextPage } = useTop({ starring });
return <List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />;
return (
<>
{Boolean(person) && (
<span className='inline-flex w-full h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground mb-2'>
Starring: {person?.name}
</span>
)}
<List pages={top?.pages || []} fetchNextPage={fetchNextPage} hasNextPage={hasNextPage} />
</>
);
}
+2
View File
@@ -3,3 +3,5 @@ import Container from './container';
export default function Top() {
return <Container />;
}
export const revalidate = 3600;
+9
View File
@@ -0,0 +1,9 @@
import { useQuery } from '@tanstack/react-query';
import API from './api';
const usePerson = ({ id }: { id: string | null }) => {
return useQuery({ enabled: Boolean(id), queryKey: ['person', id], queryFn: () => API.person({ id: id! }) });
};
export default usePerson;
+3 -3
View File
@@ -5,12 +5,12 @@ import { useSearchParams } from 'next/navigation';
import API from './api';
const useTop = () => {
const useTop = ({ starring }: { starring: string | null }) => {
const page = useSearchParams().get('page');
return useInfiniteQuery({
queryKey: ['top'],
queryFn: ({ pageParam: page }) => API.top({ page }),
queryKey: ['top', starring],
queryFn: ({ pageParam: page }) => API.top({ page, starring }),
suspense: true,
getNextPageParam({ page, total_pages }) {
if (page === total_pages) return undefined;