-
Notifications
You must be signed in to change notification settings - Fork 5
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
implement pagination on VASP List #988
Conversation
@@ -13,7 +13,7 @@ export function useOrganizationListQuery(): OrganizationQuery { | |||
|
|||
return { | |||
getAllOrganizations: query.refetch, | |||
organizations: query.data?.data as Organization[], | |||
organizations: query.data?.data as any, |
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.
I think it is a bad idea to add any
here because it could make debugging harder. What if you create a type based on what you get from backend ?
errorMessage?: any; | ||
getAllOrganizations(): void; | ||
reset?(): void; | ||
organizations?: any; |
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.
Would you mind adding the right type instead of any
?
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.
Sure thanks. But s story is planned to migrate all the any
type definitions. it has been added when the backend is not ready yet and was the best way to go quickly.
refreshToken?: string; | ||
} | ||
|
||
export interface organizationResponse { |
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.
export interface organizationResponse { | |
export interface OrganizationResponse { |
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.
good catch, we need to handle that with Eslint. i will create a story to check that.
|
||
export const GetAllOrganisations = async () => { | ||
const response = await axiosInstance.get(`/organizations`); | ||
export const getAllOrganisations = async (page?: number) => { |
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.
export const getAllOrganisations = async (page?: number) => { | |
export const getAllOrganisations = async (page = 1) => { |
export const GetAllOrganisations = async () => { | ||
const response = await axiosInstance.get(`/organizations`); | ||
export const getAllOrganisations = async (page?: number) => { | ||
const currentPage = page || 1; |
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.
You don't need anymore to add a default number.
const NextPage = () => { | ||
setCurrentPage(currentPage + 1); | ||
}; | ||
|
||
const PreviousPage = () => { | ||
setCurrentPage(currentPage - 1); | ||
}; | ||
|
||
useEffect(() => { | ||
if (currentPage !== 1) { | ||
getAllOrganizations(); | ||
} | ||
}, [currentPage, getAllOrganizations]); | ||
|
||
useEffect(() => { | ||
if (page && page_size && count && page * page_size >= count) { | ||
setWasLastPage(true); | ||
} | ||
return () => { | ||
setWasLastPage(false); | ||
}; | ||
}, [page, page_size, count]); |
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.
Put all this logic inside a hooks will make those logics more testable if you planned to write unit tests
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
// useEffect(() => { | ||
// if (prevPage !== currentPage) { | ||
// setPrevPage(currentPage + 1); | ||
// if (organizations && organizations.organizations.length === 0) { | ||
// setOrgList([...orgList, ...organizations.organizations]); | ||
// } | ||
// } | ||
// }, [currentPage, organizations, orgList, prevPage]); | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
// const onScroll = () => { | ||
// if (listInnerRef.current) { | ||
// const { scrollTop, scrollHeight, clientHeight } = listInnerRef.current; | ||
// // console.log('[scrollTop]', scrollTop); | ||
// // console.log('[scrollHeight]', scrollHeight); | ||
// // console.log('[clientHeight]', clientHeight); | ||
// // console.log('[scrollTop + clientHeight]', scrollTop + clientHeight); | ||
|
||
// if (scrollTop + clientHeight === scrollHeight) { | ||
// setCurrentPage(currentPage + 1); | ||
// } | ||
// } | ||
// }; | ||
|
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.
Did you planned to use this logic later ?
@@ -76,6 +143,14 @@ function ChooseAnOrganization() { | |||
</Stack> | |||
</Stack> | |||
</Stack> | |||
<HStack> | |||
<Button onClick={PreviousPage} disabled={currentPage === 1}> |
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.
We can create here something like isCurrentPage
and add it inside a hooks (#988 (comment))
<Button onClick={PreviousPage} disabled={currentPage === 1}> | |
<Button onClick={PreviousPage} disabled={isCurrentPage}> |
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! I have asked some questions and suggested changements at some level
Scope of changes
feat: implement pagination
Type of change
Acceptance criteria
https://www.awesomescreenshot.com/video/15983926?key=520bc0334afaaa0566d399dca5c9c2db
Author checklist
Reviewer(s) checklist