-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes PaginationControl upper page limit is always 100 #151
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works, but some of the math is already done for you if you take advantage of the api query parameters.
frontend/src/components/Home.js
Outdated
@@ -83,25 +83,36 @@ export default function Home() { | |||
|
|||
useEffect(() => { | |||
let url = `${API_HOST}/leads?page=${page}&perpage=${perpage}`; | |||
const n_pagesUrl = `${API_HOST}/leads/n_pages`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you check the swagger docs, there is a perpage
query parameter to /leads/n_pages
. It should save you from redoing the math that is done on the backend.
const n_pagesUrl = `${API_HOST}/leads/n_pages`; | |
const n_pagesUrl = `${API_HOST}/leads/n_pages?perpage=${perpage}`; |
frontend/src/components/Home.js
Outdated
}) | ||
.then((response) => checkForErrors(response)) | ||
.then((data) => | ||
setMaxPages(Math.ceil((data.pages * data.query.perpage) / perpage)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This math is already done on the backend. See my first comment.
setMaxPages(Math.ceil((data.pages * data.query.perpage) / perpage)) | |
setMaxPages(data.pages) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks @TueNguyen2911 !
This PR fixes #134
maxpages
is no longer always 100maxpages
changes accordingly with theperpage