fix: use lazy pagination (#563)
This commit is contained in:
parent
59d0cfa10e
commit
c8a7e6e7e7
3
app.vue
3
app.vue
|
@ -13,8 +13,7 @@ const { params } = useRoute()
|
||||||
<template>
|
<template>
|
||||||
<NuxtLoadingIndicator color="repeating-linear-gradient(to right,var(--c-primary) 0%,var(--c-primary-active) 100%)" />
|
<NuxtLoadingIndicator color="repeating-linear-gradient(to right,var(--c-primary) 0%,var(--c-primary-active) 100%)" />
|
||||||
<NuxtLayout :key="key">
|
<NuxtLayout :key="key">
|
||||||
<!-- TODO: rework the /[account] routes to remove conditional loading -->
|
<NuxtPage />
|
||||||
<NuxtPage v-if="(!params.account && $route.path !== '/signin/callback') || isMastoInitialised" />
|
|
||||||
</NuxtLayout>
|
</NuxtLayout>
|
||||||
<AriaAnnouncer />
|
<AriaAnnouncer />
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { useDeactivated } from './lifecycle'
|
||||||
import type { PaginatorState } from '~/types'
|
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') {
|
||||||
const state = ref<PaginatorState>('idle')
|
const state = ref<PaginatorState>(isMastoInitialised.value ? 'idle' : 'loading')
|
||||||
const items = ref<T[]>([])
|
const items = ref<T[]>([])
|
||||||
const nextItems = ref<T[]>([])
|
const nextItems = ref<T[]>([])
|
||||||
const prevItems = ref<T[]>([])
|
const prevItems = ref<T[]>([])
|
||||||
|
@ -74,6 +74,13 @@ export function usePaginator<T>(paginator: Paginator<any, T[]>, stream?: WsEvent
|
||||||
bound.update()
|
bound.update()
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
|
if (!isMastoInitialised.value) {
|
||||||
|
watchOnce(isMastoInitialised, () => {
|
||||||
|
state.value = 'idle'
|
||||||
|
loadNext()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => [isInScreen, state],
|
() => [isInScreen, state],
|
||||||
() => {
|
() => {
|
||||||
|
|
|
@ -294,6 +294,17 @@ export const createMasto = () => {
|
||||||
if (!api.value) {
|
if (!api.value) {
|
||||||
return new Proxy({}, {
|
return new Proxy({}, {
|
||||||
get(_, subkey) {
|
get(_, subkey) {
|
||||||
|
if (typeof subkey === 'string' && subkey.startsWith('iterate')) {
|
||||||
|
return (...args: any[]) => {
|
||||||
|
let paginator: any
|
||||||
|
function next() {
|
||||||
|
paginator = paginator || (api.value as any)?.[key][subkey](...args)
|
||||||
|
return paginator.next()
|
||||||
|
}
|
||||||
|
return { next }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (...args: any[]) => apiPromise.value?.then((r: any) => r[key][subkey](...args))
|
return (...args: any[]) => apiPromise.value?.then((r: any) => r[key][subkey](...args))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,20 @@
|
||||||
export default defineNuxtRouteMiddleware((to) => {
|
export default defineNuxtRouteMiddleware((to) => {
|
||||||
if (process.server)
|
if (process.server)
|
||||||
return
|
return
|
||||||
if (!currentUser.value && to.path !== '/signin/callback')
|
if (to.path === '/signin/callback')
|
||||||
|
return
|
||||||
|
|
||||||
|
if (!isMastoInitialised.value) {
|
||||||
|
watchOnce(isMastoInitialised, () => {
|
||||||
|
if (!currentUser.value)
|
||||||
|
return navigateTo(`/${currentServer.value}/public`)
|
||||||
|
if (to.path === '/')
|
||||||
|
return navigateTo('/home')
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!currentUser.value)
|
||||||
return navigateTo(`/${currentServer.value}/public`)
|
return navigateTo(`/${currentServer.value}/public`)
|
||||||
if (to.path === '/')
|
if (to.path === '/')
|
||||||
return navigateTo('/home')
|
return navigateTo('/home')
|
||||||
|
|
Loading…
Reference in a new issue