feat: following and followers routes (#4)

This commit is contained in:
patak 2022-11-15 16:56:11 +01:00 committed by GitHub
parent 39249e378f
commit a6a189ba59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 127 additions and 39 deletions

41
composables/paginator.ts Normal file
View file

@ -0,0 +1,41 @@
import type { Paginator } from 'masto'
export function usePaginator<T>(paginator: Paginator<any, T[]>) {
let isLoading = $ref(false)
let isDone = $ref(false)
const items = $ref<T[]>([])
const endAnchor = ref<HTMLDivElement>()
const bound = reactive(useElementBounding(endAnchor))
const isInScreen = $computed(() => bound.top < window.innerHeight * 2)
async function loadNext() {
if (isLoading || isDone)
return
isLoading = true
const result = await paginator.next()
if (result.done)
isDone = true
if (result.value?.length)
items.push(...result.value)
isLoading = false
await nextTick()
bound.update()
}
useIntervalFn(() => {
bound.update()
}, 1000)
watch(
() => isInScreen,
() => {
if (isInScreen && !isLoading)
loadNext()
},
{ immediate: true },
)
return { items, isLoading, isDone, endAnchor }
}