-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(con): pagination for the 'Find a mentor' page (#968)
* Fix padding for the nav bar * Add pagination for the 'Find A Mentor' page * Refactor pagination logic into a helper function * Refactor
- Loading branch information
1 parent
6cc7930
commit 5ff4538
Showing
5 changed files
with
98 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
interface PaginateItemsParameters<T> { | ||
items: Array<T> | ||
currentPageNumber: number | ||
itemsPerPage: number | ||
} | ||
|
||
interface PaginateItemsResult<T> { | ||
currentItems: Array<T> | ||
totalItems: number | ||
totalPagesNumber: number | ||
} | ||
|
||
export const paginateItems = <T>({ | ||
items, | ||
currentPageNumber, | ||
itemsPerPage, | ||
}: PaginateItemsParameters<T>): PaginateItemsResult<T> => { | ||
const lastItemIndex = currentPageNumber * itemsPerPage | ||
const firstItemIndex = lastItemIndex - itemsPerPage | ||
const currentItems = items?.slice(firstItemIndex, lastItemIndex) | ||
|
||
const totalItems = items?.length | ||
const totalPagesNumber = totalItems | ||
? Math.ceil(totalItems / itemsPerPage) | ||
: undefined | ||
|
||
return { currentItems, totalItems, totalPagesNumber } | ||
} |