-
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c7de1a4
Fixes maxpages always shows 100
TueeNguyen e0e077b
Adding marginLeft to result textField
TueeNguyen 669fd32
Fixes button still increases page when page >= maxages and marginLeft
TueeNguyen e5a8cea
Merge branch 'main' of https://github.com/TueNguyen2911/partner-finder
TueeNguyen 4112b3d
Run Prettier to format code style
TueeNguyen d0c1b7a
Removing unnecessary math to calculate maxpages
TueeNguyen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -61,8 +61,8 @@ export default function Home() { | |||||
|
||||||
const [page, setPage] = useState(1); | ||||||
const [perpage, setPerpage] = useState(10); | ||||||
const [maxpages, setMaxPages] = useState(100); | ||||||
const [search, setSearch] = useState(''); | ||||||
|
||||||
const [leads, setLeads] = useState([]); | ||||||
|
||||||
const history = useHistory(); | ||||||
|
@@ -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`; | ||||||
if (search) { | ||||||
url += `&search=${search}`; | ||||||
} | ||||||
const token = localStorage.getItem('partnerFinderToken'); | ||||||
if (!token) { | ||||||
history.push('/login'); | ||||||
} | ||||||
const headers = { | ||||||
'Content-Type': 'application/json', | ||||||
Authorization: `Bearer ${token}`, | ||||||
}; | ||||||
fetch(url, { | ||||||
headers: { | ||||||
'Content-Type': 'application/json', | ||||||
Authorization: `Bearer ${token}`, | ||||||
}, | ||||||
headers: headers, | ||||||
}) | ||||||
.then((response) => checkForErrors(response)) | ||||||
.then((data) => setLeads(data.leads)) | ||||||
// TODO: create state for error and set state instead of just console.error | ||||||
// conditional rendering if there is an error | ||||||
.catch((error) => console.error(error.message)); | ||||||
}, [page, perpage, search]); | ||||||
|
||||||
fetch(n_pagesUrl, { | ||||||
headers: headers, | ||||||
}) | ||||||
.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 commentThe 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
|
||||||
) | ||||||
.catch((error) => console.error(error.message)); | ||||||
}, [page, perpage, maxpages, search]); | ||||||
|
||||||
return ( | ||||||
<div id="home"> | ||||||
|
@@ -132,7 +143,7 @@ export default function Home() { | |||||
<PaginationControl | ||||||
page={page} | ||||||
perpage={perpage} | ||||||
maxpages={100} | ||||||
maxpages={maxpages} | ||||||
setPage={setPage} | ||||||
setPerpage={setPerpage} | ||||||
/> | ||||||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.