feat: connected replies in home (#572)

This commit is contained in:
patak 2022-12-27 18:47:05 +01:00 committed by GitHub
parent 1c61aef83b
commit 4f3a065927
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 10 deletions

View file

@ -2,7 +2,12 @@ import type { Paginator, WsEvents } from 'masto'
import { useDeactivated } from './lifecycle'
import type { PaginatorState } from '~/types'
export function usePaginator<T>(paginator: Paginator<any, T[]>, stream?: WsEvents, eventType: 'notification' | 'update' = 'update') {
export function usePaginator<T>(
paginator: Paginator<any, T[]>,
stream?: WsEvents,
eventType: 'notification' | 'update' = 'update',
preprocess: (items: T[]) => T[] = (items: T[]) => items,
) {
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
const items = ref<T[]>([])
const nextItems = ref<T[]>([])
@ -52,7 +57,7 @@ export function usePaginator<T>(paginator: Paginator<any, T[]>, stream?: WsEvent
const result = await paginator.next()
if (result.value?.length) {
nextItems.value = result.value
nextItems.value = preprocess(result.value) as any
items.value.push(...nextItems.value)
state.value = 'idle'
}