From 1a3935b3abadb21065bcfe9a6cb9f2ec5da568e2 Mon Sep 17 00:00:00 2001 From: Benjamin Grilleres Date: Tue, 29 Oct 2024 10:17:14 +0100 Subject: [PATCH] fix: add logs to debug navigation --- .../components/navigation/navigation.hooks.ts | 24 ++++++++++++++++--- .../components/navigation/navigation.tsx | 3 ++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/front/src/common/components/navigation/navigation.hooks.ts b/front/src/common/components/navigation/navigation.hooks.ts index 267545b56..0f9fa2f7d 100644 --- a/front/src/common/components/navigation/navigation.hooks.ts +++ b/front/src/common/components/navigation/navigation.hooks.ts @@ -8,7 +8,9 @@ import { getNeighborsInfos } from "./navigation.utils" * @returns An array containing all ids */ const mapToNeighbors = (map: Map) => - [...map.entries()].sort((a, b) => a[0] - b[0]).flatMap(([, values]) => values) + Array.from(map.entries()) + .sort((a, b) => a[0] - b[0]) + .reduce((acc, [, values]) => acc.concat(values), [] as number[]) /** * Return an array of booleans to know if the current id has next/previous id @@ -38,7 +40,18 @@ export function useNavigation( hasPrevCurrentPage, hasNextCurrentPage, } = getNeighborsInfos(idsMap, current, currentPage, pageCount) - + console.log("infos 1", { + idsMap, + current, + currentPage, + pageCount, + neighbors, + index, + isOut, + hasPrev, + hasNext, + res: JSON.stringify(idsMap.entries()), + }) const prev = useCallback(() => { if (hasPrev && neighbors[index - 1]) { const searchParams = new URLSearchParams(location.search) @@ -62,7 +75,12 @@ export function useNavigation( const next = useCallback(() => { const searchParams = new URLSearchParams(location.search) const searchParamPage = parseInt(searchParams.get("page") ?? "1") - + console.log("infos 2", { + searchParams, + searchParamPage, + neighbors, + isOut, + }) if (isOut && neighbors[0]) { // Remove page param to restart page searchParams.delete("page") diff --git a/front/src/common/components/navigation/navigation.tsx b/front/src/common/components/navigation/navigation.tsx index 75ab5e4a9..dc0db9e0f 100644 --- a/front/src/common/components/navigation/navigation.tsx +++ b/front/src/common/components/navigation/navigation.tsx @@ -82,11 +82,12 @@ 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 } + console.log("valeur de id map", JSON.stringify(idsMap.entries())) const { loading } = useQuery( // eslint-disable-next-line @typescript-eslint/no-unused-vars