2022-11-16 16:11:08 +00:00
|
|
|
<script setup lang="ts">
|
2022-11-27 06:16:02 +00:00
|
|
|
// @ts-expect-error missing types
|
2022-11-26 19:57:59 +00:00
|
|
|
import { DynamicScroller } from 'vue-virtual-scroller'
|
|
|
|
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
|
2022-11-28 11:18:45 +00:00
|
|
|
import type { Paginator, WsEvents } from 'masto'
|
2022-11-16 16:11:08 +00:00
|
|
|
|
2022-11-28 11:18:45 +00:00
|
|
|
const { paginator, stream, keyProp = 'id', virtualScroller = false } = defineProps<{
|
2022-11-17 07:35:42 +00:00
|
|
|
paginator: Paginator<any, any[]>
|
|
|
|
keyProp?: string
|
2022-11-28 13:14:27 +00:00
|
|
|
virtualScroller?: boolean
|
2022-11-28 11:18:45 +00:00
|
|
|
stream?: WsEvents
|
2022-11-16 16:11:08 +00:00
|
|
|
}>()
|
2022-11-17 07:35:42 +00:00
|
|
|
|
2022-11-27 08:54:00 +00:00
|
|
|
defineSlots<{
|
|
|
|
default: {
|
|
|
|
item: any
|
|
|
|
active?: boolean
|
|
|
|
}
|
2022-11-28 11:18:45 +00:00
|
|
|
updater: {
|
|
|
|
number: number
|
|
|
|
update: () => void
|
|
|
|
}
|
2022-11-27 08:54:00 +00:00
|
|
|
loading: {}
|
|
|
|
}>()
|
|
|
|
|
2022-11-28 11:18:45 +00:00
|
|
|
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream)
|
2022-11-16 16:11:08 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-17 07:35:42 +00:00
|
|
|
<div>
|
2022-11-28 11:18:45 +00:00
|
|
|
<slot v-if="prevItems.length" name="updater" v-bind="{ number: prevItems.length, update }" />
|
2022-11-26 19:57:59 +00:00
|
|
|
<template v-if="virtualScroller">
|
2022-11-27 13:12:25 +00:00
|
|
|
<DynamicScroller
|
|
|
|
v-slot="{ item, active }"
|
|
|
|
:items="items"
|
|
|
|
:min-item-size="200"
|
|
|
|
:key-field="keyProp"
|
|
|
|
page-mode
|
|
|
|
>
|
2022-11-26 19:57:59 +00:00
|
|
|
<slot :item="item" :active="active" />
|
|
|
|
</DynamicScroller>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<slot
|
|
|
|
v-for="item of items"
|
|
|
|
:key="item[keyProp]"
|
|
|
|
:item="item"
|
|
|
|
/>
|
|
|
|
</template>
|
2022-11-17 07:35:42 +00:00
|
|
|
<div ref="endAnchor" />
|
2022-11-27 05:02:19 +00:00
|
|
|
<slot v-if="state === 'loading'" name="loading">
|
|
|
|
<div p5 text-center flex="~ col" items-center animate-pulse>
|
|
|
|
<div text-secondary i-ri:loader-2-fill animate-spin text-2xl />
|
2022-11-29 23:25:29 +00:00
|
|
|
<span text-secondary>{{ $t('state.loading') }}</span>
|
2022-11-27 05:02:19 +00:00
|
|
|
</div>
|
|
|
|
</slot>
|
2022-11-26 20:41:18 +00:00
|
|
|
<div v-else-if="state === 'done'" p5 text-secondary italic text-center>
|
2022-11-29 10:55:28 +00:00
|
|
|
{{ $t('common.end_of_list') }}
|
2022-11-17 07:35:42 +00:00
|
|
|
</div>
|
2022-11-26 20:41:18 +00:00
|
|
|
<div v-else-if="state === 'error'" p5 text-secondary>
|
2022-11-29 10:55:28 +00:00
|
|
|
{{ $t('common.error') }}: {{ error }}
|
2022-11-17 07:35:42 +00:00
|
|
|
</div>
|
2022-11-16 16:11:08 +00:00
|
|
|
</div>
|
|
|
|
</template>
|