From 38f0ca26daeaae76f80d9c3639e864b069f7a4fb Mon Sep 17 00:00:00 2001 From: ner Date: Sat, 19 Oct 2024 19:33:02 +0300 Subject: [PATCH] fix: favorites pagination --- api/index.ts | 9 ++++++--- app/(site)/favorites/page.tsx | 2 +- app/(site)/watch-list/page.tsx | 2 +- hooks/useUsersShows.ts | 5 +++-- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/api/index.ts b/api/index.ts index 10bc2f3..41a5e80 100644 --- a/api/index.ts +++ b/api/index.ts @@ -1,5 +1,7 @@ 'use server'; +import { cookies } from 'next/headers'; + import { createUniqueRandomGenerator } from '@/lib/utils'; import mapMoviesSeriesResponseToShows, { mapMovieSeriesToShow } from './dto/Show'; @@ -7,7 +9,6 @@ import pirateBay from './parsers/pirate-bay'; import yts from './parsers/yts'; import http from './Http'; import { Sort } from './parsers'; -import { cookies } from 'next/headers'; export const createRequestToken = async () => { return http.get('/authentication/token/new', { preventCache: true }).then(({ request_token }) => ({ @@ -61,14 +62,16 @@ export const updateAccountStates = async ({ export const usersShows = async ({ showType, - list + list, + page }: { showType: Show['type']; list: 'favorite' | 'watchlist'; + page: string; }): Promise> => { return http .get>(`/account/null/${list}/${showType === 'tv' ? 'tv' : 'movies'}`, { - params: { session_id: cookies().get('session')?.value }, + params: { page, session_id: cookies().get('session')?.value }, preventCache: true }) .then((response) => mapMoviesSeriesResponseToShows(response, showType)); diff --git a/app/(site)/favorites/page.tsx b/app/(site)/favorites/page.tsx index 1c71ccd..e81ff78 100644 --- a/app/(site)/favorites/page.tsx +++ b/app/(site)/favorites/page.tsx @@ -20,7 +20,7 @@ const Favorites = async () => { await queryClient.prefetchInfiniteQuery({ queryKey: [`users-${list}`, showType], - queryFn: () => usersShows({ showType, list }), + queryFn: () => usersShows({ showType, list, page: '1' }), initialPageParam: '1' }); diff --git a/app/(site)/watch-list/page.tsx b/app/(site)/watch-list/page.tsx index 56f672a..3f2b988 100644 --- a/app/(site)/watch-list/page.tsx +++ b/app/(site)/watch-list/page.tsx @@ -20,7 +20,7 @@ const WatchList = async () => { await queryClient.prefetchInfiniteQuery({ queryKey: [`users-${list}`, showType], - queryFn: () => usersShows({ showType, list }), + queryFn: () => usersShows({ showType, list, page: '1' }), initialPageParam: '1' }); diff --git a/hooks/useUsersShows.ts b/hooks/useUsersShows.ts index 153555c..770a379 100644 --- a/hooks/useUsersShows.ts +++ b/hooks/useUsersShows.ts @@ -1,7 +1,8 @@ import { usersShows } from '@/api'; + import useInfiniteList from './useInfiniteList'; -import { useSession } from './useSession'; import { useFavorites, useWatchList } from './useLocalUsersLists'; +import { useSession } from './useSession'; export const KEY = ({ list, showType }: { showType: Show['type']; list: 'favorite' | 'watchlist' }) => [ `users-${list}`, @@ -16,7 +17,7 @@ const useUsersShows = ({ showType, list = 'favorite' }: { showType: Show['type'] const query = useInfiniteList({ queryKey: KEY({ list, showType }), - queryFn: () => usersShows({ showType, list }), + queryFn: ({ page }) => usersShows({ showType, list, page }), enabled: Boolean(session) });