diff --git a/front/src/common/components/navigation/navigation.hooks.ts b/front/src/common/components/navigation/navigation.hooks.ts index 267545b56..c48ff3490 100644 --- a/front/src/common/components/navigation/navigation.hooks.ts +++ b/front/src/common/components/navigation/navigation.hooks.ts @@ -44,11 +44,13 @@ export function useNavigation( const searchParams = new URLSearchParams(location.search) const searchParamPage = searchParams.get("page") - // Change page query param when the next id is on a new page - if (searchParamPage && parseInt(searchParamPage) - 1 === 1) { - searchParams.delete("page") - } else if (!hasPrevCurrentPage && searchParamPage) { - searchParams.set("page", `${parseInt(searchParamPage) - 1}`) + + // Update page query param when the current id is the last id of the current page + if (!hasPrevCurrentPage && searchParamPage) { + const prevPage = parseInt(searchParamPage) - 1 + + if (prevPage === 1) searchParams.delete("page") + else searchParams.set("page", prevPage.toString()) } navigate({ diff --git a/front/src/common/components/navigation/navigation.tsx b/front/src/common/components/navigation/navigation.tsx index 75ab5e4a9..c4a86dfb2 100644 --- a/front/src/common/components/navigation/navigation.tsx +++ b/front/src/common/components/navigation/navigation.tsx @@ -82,12 +82,11 @@ const NavigationButtons = ({ const items = await fetchIdsForPage(page) if (items && !idsMap.has(page)) { - setIdsMap(idsMap.set(page, getItemsIds(items))) + setIdsMap(new Map(idsMap.set(page, getItemsIds(items)))) } return items } - const { loading } = useQuery( // eslint-disable-next-line @typescript-eslint/no-unused-vars (current: number) => fetchIdsForNavigation(page), @@ -102,9 +101,11 @@ const NavigationButtons = ({ pageCount ) + // Fetch previous page only if the current id is first id of the current page and there is a previous page if (infos.hasPrev && !infos.hasPrevCurrentPage) { fetchIdsForNavigation(page - 1) - } else if (nav.hasNext && !infos.hasNextCurrentPage) { + } else if (infos.hasNext && !infos.hasNextCurrentPage) { + // Fetch next page only if the current id is last id of the current page and there is a next page fetchIdsForNavigation(page + 1) } },