feat: avoid reordering pagination border effects (#877)
This commit is contained in:
parent
f8692ed480
commit
efe406df5b
8 changed files with 19 additions and 10 deletions
|
@ -6,6 +6,7 @@ export function usePaginator<T, P>(
|
|||
stream?: Promise<WsEvents>,
|
||||
eventType: 'notification' | 'update' = 'update',
|
||||
preprocess: (items: T[]) => T[] = (items: T[]) => items,
|
||||
buffer = 10,
|
||||
) {
|
||||
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
|
||||
const items = ref<T[]>([])
|
||||
|
@ -62,8 +63,10 @@ export function usePaginator<T, P>(
|
|||
const result = await paginator.next()
|
||||
|
||||
if (result.value?.length) {
|
||||
nextItems.value = preprocess(result.value) as any
|
||||
items.value.push(...nextItems.value)
|
||||
const preprocessedItems = preprocess([...nextItems.value, ...result.value]) as any
|
||||
const itemsToShowCount = preprocessedItems.length - buffer
|
||||
nextItems.value = preprocessedItems.slice(itemsToShowCount)
|
||||
items.value.push(...preprocessedItems.slice(0, itemsToShowCount))
|
||||
state.value = 'idle'
|
||||
}
|
||||
else {
|
||||
|
@ -108,7 +111,6 @@ export function usePaginator<T, P>(
|
|||
return {
|
||||
items,
|
||||
prevItems,
|
||||
nextItems,
|
||||
update,
|
||||
state,
|
||||
error,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue