Adding loading control to make sure that pagination can't be spammed in between loads.

This commit is contained in:
mike12345567 2022-06-30 17:02:50 +01:00
parent b7b74ee2ad
commit 44d478c317
2 changed files with 13 additions and 2 deletions

View File

@ -6,6 +6,7 @@ function defaultValue() {
page: undefined,
hasPrevPage: false,
hasNextPage: false,
loading: false,
pageNumber: 1,
pages: [],
}
@ -38,6 +39,14 @@ export function createPaginationStore() {
update(state => {
state.hasNextPage = hasNextPage
state.nextPage = nextPage
state.loading = false
return state
})
}
function loading(loading = true) {
update(state => {
state.loading = loading
return state
})
}
@ -51,6 +60,7 @@ export function createPaginationStore() {
prevPage,
nextPage,
fetched,
loading,
reset,
}
}

View File

@ -35,6 +35,7 @@
async function fetchUsers(page, search) {
try {
pageInfo.loading()
await users.search({ page, search })
pageInfo.fetched($users.hasNextPage, $users.nextPage)
} catch (error) {
@ -78,8 +79,8 @@
<div class="pagination">
<Pagination
page={$pageInfo.pageNumber}
hasPrevPage={$pageInfo.hasPrevPage}
hasNextPage={$pageInfo.hasNextPage}
hasPrevPage={$pageInfo.loading ? false : $pageInfo.hasPrevPage}
hasNextPage={$pageInfo.loading ? false : $pageInfo.hasNextPage}
goToPrevPage={pageInfo.prevPage}
goToNextPage={pageInfo.nextPage}
/>