Skip to content

Commit

Permalink
Merge branch 'hotfix/modal-navigation' into 'master'
Browse files Browse the repository at this point in the history
Hotfix/modal navigation

See merge request la-fabrique-numerique/biocarburants!221
  • Loading branch information
benjamin-grilleres committed Oct 29, 2024
2 parents 3fbc79d + d0ee705 commit 8b32faf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
12 changes: 7 additions & 5 deletions front/src/common/components/navigation/navigation.hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
7 changes: 4 additions & 3 deletions front/src/common/components/navigation/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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)
}
},
Expand Down

0 comments on commit 8b32faf

Please sign in to comment.