Skip to content

Commit

Permalink
chore: event-log pagination update (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean authored Dec 14, 2023
1 parent 3af12e9 commit 2c6ed4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ class SSIKit2WalletService(tenant: String?, accountId: UUID, walletId: UUID) :
EventLogFilterDataResult(
items = events,
count = events.size,
currentStartingAfter = computeCurrentStartingAfter(startingAfterItemIndex, pageSize),
currentStartingAfter = computeCurrentStartingAfter(startingAfterItemIndex),
nextStartingAfter = computeNextStartingAfter(startingAfterItemIndex, pageSize, count)
)
}.fold(onSuccess = {
Expand Down Expand Up @@ -758,14 +758,13 @@ class SSIKit2WalletService(tenant: String?, accountId: UUID, walletId: UUID) :
)

//TODO: move to related entity
private fun computeCurrentStartingAfter(afterItemIndex: Long, pageSize: Int): String? = let {
val itemIndex = afterItemIndex - pageSize
itemIndex.takeIf { it >= -1 }?.toString()
private fun computeCurrentStartingAfter(afterItemIndex: Long): String? = let {
afterItemIndex.takeIf { it >= 0 }?.toString()
}

//TODO: move to related entity
private fun computeNextStartingAfter(afterItemIndex: Long, pageSize: Int, count: Long): String? = let {
val itemIndex = afterItemIndex + pageSize
itemIndex.takeIf { it <= count }?.toString()
itemIndex.takeIf { it < count }?.toString()
}
}
12 changes: 6 additions & 6 deletions waltid-web-wallet/web/src/pages/wallet/[wallet]/eventlog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<div class="flex flex-none items-center gap-x-4">
<button
v-if="eventLog?.currentStartingAfter"
@click="prevPage(eventLog.currentStartingAfter)"
@click="topPage('-1')"
class="hidden rounded-md bg-white px-2.5 py-1.5 text-sm font-semibold text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 hover:bg-gray-50 sm:block"
>Previous
>Top
</button>
</div>
<div class="flex flex-none items-center gap-x-4">
Expand Down Expand Up @@ -129,7 +129,7 @@ const { data: eventLog, pending: pending } = await useLazyAsyncData(
() =>
$fetch(`/wallet-api/wallet/${currentWallet.value}/eventlog`, {
params: {
limit: 4,
limit: 2,
startingAfter: startingAfter.value,
},
}),
Expand All @@ -148,12 +148,12 @@ function viewData(title, data) {
},
});
}
function prevPage(startingAfterParam){
console.log(`prev.page: ${startingAfterParam}`)
function topPage(startingAfterParam){
console.log(`top: ${startingAfterParam}`)
startingAfter.value = startingAfterParam
}
function nextPage(startingAfterParam){
console.log(`next.page: ${startingAfterParam}`)
console.log(`next: ${startingAfterParam}`)
startingAfter.value = startingAfterParam
}
</script>
Expand Down

0 comments on commit 2c6ed4c

Please sign in to comment.