fix: favorites pagination
This commit is contained in:
1 parent
8858e47d38
commit
38f0ca26da
4 files changed
+11
-7
No files matched your search
+6
-3
@@ -1,5 +1,7 @@
|
|||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
import { cookies } from 'next/headers';
|
||||||
|
|
||||||
import { createUniqueRandomGenerator } from '@/lib/utils';
|
import { createUniqueRandomGenerator } from '@/lib/utils';
|
||||||
|
|
||||||
import mapMoviesSeriesResponseToShows, { mapMovieSeriesToShow } from './dto/Show';
|
import mapMoviesSeriesResponseToShows, { mapMovieSeriesToShow } from './dto/Show';
|
||||||
@@ -7,7 +9,6 @@ import pirateBay from './parsers/pirate-bay';
|
|||||||
import yts from './parsers/yts';
|
import yts from './parsers/yts';
|
||||||
import http from './Http';
|
import http from './Http';
|
||||||
import { Sort } from './parsers';
|
import { Sort } from './parsers';
|
||||||
import { cookies } from 'next/headers';
|
|
||||||
|
|
||||||
export const createRequestToken = async () => {
|
export const createRequestToken = async () => {
|
||||||
return http.get<RequestToken>('/authentication/token/new', { preventCache: true }).then(({ request_token }) => ({
|
return http.get<RequestToken>('/authentication/token/new', { preventCache: true }).then(({ request_token }) => ({
|
||||||
@@ -61,14 +62,16 @@ export const updateAccountStates = async ({
|
|||||||
|
|
||||||
export const usersShows = async ({
|
export const usersShows = async ({
|
||||||
showType,
|
showType,
|
||||||
list
|
list,
|
||||||
|
page
|
||||||
}: {
|
}: {
|
||||||
showType: Show['type'];
|
showType: Show['type'];
|
||||||
list: 'favorite' | 'watchlist';
|
list: 'favorite' | 'watchlist';
|
||||||
|
page: string;
|
||||||
}): Promise<Pagination<Show>> => {
|
}): Promise<Pagination<Show>> => {
|
||||||
return http
|
return http
|
||||||
.get<TMDBPagination<Movie>>(`/account/null/${list}/${showType === 'tv' ? 'tv' : 'movies'}`, {
|
.get<TMDBPagination<Movie>>(`/account/null/${list}/${showType === 'tv' ? 'tv' : 'movies'}`, {
|
||||||
params: { session_id: cookies().get('session')?.value },
|
params: { page, session_id: cookies().get('session')?.value },
|
||||||
preventCache: true
|
preventCache: true
|
||||||
})
|
})
|
||||||
.then((response) => mapMoviesSeriesResponseToShows(response, showType));
|
.then((response) => mapMoviesSeriesResponseToShows(response, showType));
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const Favorites = async () => {
|
|||||||
|
|
||||||
await queryClient.prefetchInfiniteQuery({
|
await queryClient.prefetchInfiniteQuery({
|
||||||
queryKey: [`users-${list}`, showType],
|
queryKey: [`users-${list}`, showType],
|
||||||
queryFn: () => usersShows({ showType, list }),
|
queryFn: () => usersShows({ showType, list, page: '1' }),
|
||||||
initialPageParam: '1'
|
initialPageParam: '1'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ const WatchList = async () => {
|
|||||||
|
|
||||||
await queryClient.prefetchInfiniteQuery({
|
await queryClient.prefetchInfiniteQuery({
|
||||||
queryKey: [`users-${list}`, showType],
|
queryKey: [`users-${list}`, showType],
|
||||||
queryFn: () => usersShows({ showType, list }),
|
queryFn: () => usersShows({ showType, list, page: '1' }),
|
||||||
initialPageParam: '1'
|
initialPageParam: '1'
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import { usersShows } from '@/api';
|
import { usersShows } from '@/api';
|
||||||
|
|
||||||
import useInfiniteList from './useInfiniteList';
|
import useInfiniteList from './useInfiniteList';
|
||||||
import { useSession } from './useSession';
|
|
||||||
import { useFavorites, useWatchList } from './useLocalUsersLists';
|
import { useFavorites, useWatchList } from './useLocalUsersLists';
|
||||||
|
import { useSession } from './useSession';
|
||||||
|
|
||||||
export const KEY = ({ list, showType }: { showType: Show['type']; list: 'favorite' | 'watchlist' }) => [
|
export const KEY = ({ list, showType }: { showType: Show['type']; list: 'favorite' | 'watchlist' }) => [
|
||||||
`users-${list}`,
|
`users-${list}`,
|
||||||
@@ -16,7 +17,7 @@ const useUsersShows = ({ showType, list = 'favorite' }: { showType: Show['type']
|
|||||||
|
|
||||||
const query = useInfiniteList({
|
const query = useInfiniteList({
|
||||||
queryKey: KEY({ list, showType }),
|
queryKey: KEY({ list, showType }),
|
||||||
queryFn: () => usersShows({ showType, list }),
|
queryFn: ({ page }) => usersShows({ showType, list, page }),
|
||||||
enabled: Boolean(session)
|
enabled: Boolean(session)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user