feat: added favorites page
This commit is contained in:
1 parent
0cb860d0a0
commit
89e76f5df6
27 files changed
+412
-116
No files matched your search
+10
-1
@@ -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
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -3,3 +3,5 @@ import Container from './container';
|
||||
export default function Top() {
|
||||
return <Container />;
|
||||
}
|
||||
|
||||
export const revalidate = 3600;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user