Skip to content
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

Merged
merged 6 commits into from
Oct 7, 2021

Conversation

TueeNguyen
Copy link
Collaborator

This PR fixes #134

  • maxpages is no longer always 100

image

  • maxpages changes accordingly with the perpage

image

  • Adding a margin left to results box to make it look better

Copy link
Collaborator

@galbwe galbwe left a 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.

@@ -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`;
Copy link
Collaborator

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.

Suggested change
const n_pagesUrl = `${API_HOST}/leads/n_pages`;
const n_pagesUrl = `${API_HOST}/leads/n_pages?perpage=${perpage}`;

})
.then((response) => checkForErrors(response))
.then((data) =>
setMaxPages(Math.ceil((data.pages * data.query.perpage) / perpage))
Copy link
Collaborator

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.

Suggested change
setMaxPages(Math.ceil((data.pages * data.query.perpage) / perpage))
setMaxPages(data.pages)

Copy link
Collaborator

@galbwe galbwe left a 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 !

@galbwe galbwe merged commit b34d60f into codefordenver:main Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PaginationControl upper page limit is always 100
2 participants