From 98937a03786f64bcde5a35ab085cb6926b0a7e5e Mon Sep 17 00:00:00 2001 From: LASER-Yi Date: Sat, 11 Jun 2022 19:55:29 +0800 Subject: [PATCH] Fix crash when navigating from history view and open the history modal --- frontend/src/apis/hooks/episodes.ts | 3 ++- frontend/src/apis/hooks/movies.ts | 6 ++++-- frontend/src/apis/queries/hooks.ts | 17 ++++++++++------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/frontend/src/apis/hooks/episodes.ts b/frontend/src/apis/hooks/episodes.ts index d67d2d194..c4f793047 100644 --- a/frontend/src/apis/hooks/episodes.ts +++ b/frontend/src/apis/hooks/episodes.ts @@ -99,7 +99,8 @@ export function useEpisodeDeleteBlacklist() { export function useEpisodeHistoryPagination() { return usePaginationQuery( [QueryKeys.Series, QueryKeys.Episodes, QueryKeys.History], - (param) => api.episodes.history(param) + (param) => api.episodes.history(param), + false ); } diff --git a/frontend/src/apis/hooks/movies.ts b/frontend/src/apis/hooks/movies.ts index f75a40ad3..904f6557d 100644 --- a/frontend/src/apis/hooks/movies.ts +++ b/frontend/src/apis/hooks/movies.ts @@ -123,8 +123,10 @@ export function useMovieDeleteBlacklist() { } export function useMovieHistoryPagination() { - return usePaginationQuery([QueryKeys.Movies, QueryKeys.History], (param) => - api.movies.history(param) + return usePaginationQuery( + [QueryKeys.Movies, QueryKeys.History], + (param) => api.movies.history(param), + false ); } diff --git a/frontend/src/apis/queries/hooks.ts b/frontend/src/apis/queries/hooks.ts index 0b36421ea..649eeecbd 100644 --- a/frontend/src/apis/queries/hooks.ts +++ b/frontend/src/apis/queries/hooks.ts @@ -29,7 +29,8 @@ export function usePaginationQuery< TQueryKey extends QueryKey = QueryKey >( queryKey: TQueryKey, - queryFn: RangeQuery + queryFn: RangeQuery, + cacheIndividual = false ): UsePaginationQueryResult { const client = useQueryClient(); @@ -49,12 +50,14 @@ export function usePaginationQuery< }, { onSuccess: ({ data }) => { - data.forEach((item) => { - const id = GetItemId(item); - if (id) { - client.setQueryData([...queryKey, id], item); - } - }); + if (cacheIndividual) { + data.forEach((item) => { + const id = GetItemId(item); + if (id) { + client.setQueryData([...queryKey, id], item); + } + }); + } }, } );