Skip to content

Commit

Permalink
fix: add logs to debug navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Grilleres committed Oct 29, 2024
1 parent bba6b80 commit 1a3935b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
24 changes: 21 additions & 3 deletions front/src/common/components/navigation/navigation.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { getNeighborsInfos } from "./navigation.utils"
* @returns An array containing all ids
*/
const mapToNeighbors = (map: Map<number, number[]>) =>
[...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
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion front/src/common/components/navigation/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1a3935b

Please sign in to comment.