Skip to content

Commit

Permalink
Corrige une régression d'affichage sur le composant Pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
mariheck committed Jan 10, 2025
1 parent f8a635d commit 980fcdc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,14 @@ const IndicateursListe = ({
/>
))}
</div>
<div className="flex mt-16">
<Pagination
className="mx-auto"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
onChange={(page) => setCurrentPage(page)}
/>
</div>
<Pagination
className="mx-auto mt-16"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
idToScrollTo="app-header"
onChange={setCurrentPage}
/>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,15 +188,14 @@ const PlansActionListe = ({
/>
))}
</div>
<div className="flex mt-16">
<Pagination
className="mx-auto"
selectedPage={currentPage}
nbOfElements={data?.count ?? 0}
maxElementsPerPage={maxNbOfCards}
onChange={(page) => setCurrentPage(page)}
/>
</div>
<Pagination
className="mx-auto mt-16"
selectedPage={currentPage}
nbOfElements={data?.count ?? 0}
maxElementsPerPage={maxNbOfCards}
idToScrollTo="app-header"
onChange={setCurrentPage}
/>
</div>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,15 +353,14 @@ const FichesActionListe = ({
/>
))}
</div>
<div className="flex mt-16">
<Pagination
className="mx-auto"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
onChange={(page) => setCurrentPage(page)}
/>
</div>
<Pagination
className="mx-auto mt-16"
selectedPage={currentPage}
nbOfElements={countTotal}
maxElementsPerPage={maxNbOfCards}
idToScrollTo="app-header"
onChange={setCurrentPage}
/>
</div>
)}

Expand Down
2 changes: 1 addition & 1 deletion packages/site/app/programme/annuaire/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const Annuaire = () => {
nbOfElements={total}
maxElementsPerPage={PAGINATION_LIMIT}
idToScrollTo="annuaire-header"
onChange={(selectedPage) => setSelectPage(selectedPage)}
onChange={setSelectPage}
/>
</Section>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/ui/src/design-system/Pagination/Pagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const Pagination = ({
const [nbOfPages, setNbOfPages] = useState(
Math.ceil(nbOfElements / maxElementsPerPage)
);
const [pageButtons, setPageButtons] = useState<number[]>([]);
const [pageButtons, setPageButtons] = useState<(number | undefined)[]>([]);
const [currentPage, setCurrentPage] = useState(selectedPage);
const [windowWidth, setWindowWidth] = useState<number>(0);
const [isMobile, setIsMobile] = useState(false);
Expand Down Expand Up @@ -100,7 +100,7 @@ export const Pagination = ({
key={i}
pageNumber={pageNum}
isSelected={currentPage === pageNum}
onClick={() => handleChangePage(pageNum)}
onClick={() => !!pageNum && handleChangePage(pageNum)}
/>
))}
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/ui/src/design-system/Pagination/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ export const calculatePaginationArray = ({
: undefined;

// Construction du tableau final
const finalArray = [...leftRange];
if (!displayAllPages && leftIntersection !== undefined) {
const finalArray: (number | undefined)[] = [...leftRange];

if (!displayAllPages) {
finalArray.push(leftIntersection);
}

finalArray.push(...middleRange);

if (isMiddlePage && !displayAllPages && rightIntersection !== undefined) {
if (isMiddlePage && !displayAllPages) {
finalArray.push(rightIntersection);
}

Expand Down

0 comments on commit 980fcdc

Please sign in to comment.