-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ERM-3220 Update pagination mechanisms for MCLs to work without stats
* create new hook for fetch with no stats * add hasNextPage prop to usePrevNextPagination
- Loading branch information
Showing
3 changed files
with
57 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { useMemo } from 'react'; | ||
import { useQueries } from 'react-query'; | ||
import { useOkapiKy } from '@folio/stripes/core'; | ||
import { generateKiwtQueryParams } from '@k-int/stripes-kint-components'; | ||
|
||
const usePrevNextPagination = ({ | ||
id, // for future use / local zustand store | ||
Check warning on line 7 in lib/hooks/useFetchWithNoStats.js GitHub Actions / github-actions-ci
|
||
params = {}, | ||
path = '', | ||
keyArray = [], | ||
} = {}) => { | ||
const ky = useOkapiKy(); | ||
const queryArray = []; | ||
const currentPageParams = useMemo(() => ( | ||
generateKiwtQueryParams( | ||
{ ...params, stats: false }, | ||
{} | ||
) | ||
), [params]); | ||
const currentPageParamsSpread = [...currentPageParams]; | ||
queryArray.push({ | ||
queryKey: [ | ||
path, | ||
currentPageParams, | ||
...keyArray | ||
], | ||
queryFn: () => ky.get(`${path}?${currentPageParamsSpread?.join('&')}`).json(), | ||
}); | ||
|
||
const nextPageParams = useMemo(() => ( | ||
generateKiwtQueryParams( | ||
{ ...params, page: params.page + 1, stats: false }, | ||
{} | ||
) | ||
), [params]); | ||
const nextPageParamsSpread = [...nextPageParams]; | ||
queryArray.push({ | ||
queryKey: [ | ||
path, | ||
nextPageParams, | ||
...keyArray | ||
], | ||
queryFn: () => ky.get(`${path}?${nextPageParamsSpread?.join('&')}`).json(), | ||
}); | ||
|
||
const queries = useQueries(queryArray); | ||
|
||
return ({ | ||
currentPage: queries[0], | ||
nextPage: queries[1], | ||
}); | ||
}; | ||
|
||
export default usePrevNextPagination; |
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