Adding loading control to make sure that pagination can't be spammed in between loads.
This commit is contained in:
parent
b7b74ee2ad
commit
44d478c317
|
@ -6,6 +6,7 @@ function defaultValue() {
|
||||||
page: undefined,
|
page: undefined,
|
||||||
hasPrevPage: false,
|
hasPrevPage: false,
|
||||||
hasNextPage: false,
|
hasNextPage: false,
|
||||||
|
loading: false,
|
||||||
pageNumber: 1,
|
pageNumber: 1,
|
||||||
pages: [],
|
pages: [],
|
||||||
}
|
}
|
||||||
|
@ -38,6 +39,14 @@ export function createPaginationStore() {
|
||||||
update(state => {
|
update(state => {
|
||||||
state.hasNextPage = hasNextPage
|
state.hasNextPage = hasNextPage
|
||||||
state.nextPage = nextPage
|
state.nextPage = nextPage
|
||||||
|
state.loading = false
|
||||||
|
return state
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
function loading(loading = true) {
|
||||||
|
update(state => {
|
||||||
|
state.loading = loading
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -51,6 +60,7 @@ export function createPaginationStore() {
|
||||||
prevPage,
|
prevPage,
|
||||||
nextPage,
|
nextPage,
|
||||||
fetched,
|
fetched,
|
||||||
|
loading,
|
||||||
reset,
|
reset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
|
|
||||||
async function fetchUsers(page, search) {
|
async function fetchUsers(page, search) {
|
||||||
try {
|
try {
|
||||||
|
pageInfo.loading()
|
||||||
await users.search({ page, search })
|
await users.search({ page, search })
|
||||||
pageInfo.fetched($users.hasNextPage, $users.nextPage)
|
pageInfo.fetched($users.hasNextPage, $users.nextPage)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -78,8 +79,8 @@
|
||||||
<div class="pagination">
|
<div class="pagination">
|
||||||
<Pagination
|
<Pagination
|
||||||
page={$pageInfo.pageNumber}
|
page={$pageInfo.pageNumber}
|
||||||
hasPrevPage={$pageInfo.hasPrevPage}
|
hasPrevPage={$pageInfo.loading ? false : $pageInfo.hasPrevPage}
|
||||||
hasNextPage={$pageInfo.hasNextPage}
|
hasNextPage={$pageInfo.loading ? false : $pageInfo.hasNextPage}
|
||||||
goToPrevPage={pageInfo.prevPage}
|
goToPrevPage={pageInfo.prevPage}
|
||||||
goToNextPage={pageInfo.nextPage}
|
goToNextPage={pageInfo.nextPage}
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Reference in New Issue