2022-11-16 16:11:08 +00:00
|
|
|
<script setup lang="ts">
|
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-17 07:35:42 +00:00
|
|
|
import type { Paginator } from 'masto'
|
2022-11-16 16:11:08 +00:00
|
|
|
|
2022-11-26 19:57:59 +00:00
|
|
|
const { paginator, keyProp = 'id', virtualScroller = false } = defineProps<{
|
2022-11-17 07:35:42 +00:00
|
|
|
paginator: Paginator<any, any[]>
|
|
|
|
keyProp?: string
|
2022-11-26 19:57:59 +00:00
|
|
|
virtualScroller: boolean
|
2022-11-16 16:11:08 +00:00
|
|
|
}>()
|
2022-11-17 07:35:42 +00:00
|
|
|
|
2022-11-22 13:03:36 +00:00
|
|
|
const { items, state, endAnchor, error } = usePaginator(paginator)
|
2022-11-16 16:11:08 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-17 07:35:42 +00:00
|
|
|
<div>
|
2022-11-26 19:57:59 +00:00
|
|
|
<template v-if="virtualScroller">
|
|
|
|
<DynamicScroller v-slot="{ item, active }" :items="items" :min-item-size="200" page-mode>
|
|
|
|
<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-20 20:32:20 +00:00
|
|
|
<div v-if="state === 'loading'" p5 text-center flex="~ col" items-center animate-pulse>
|
2022-11-26 20:41:18 +00:00
|
|
|
<div text-secondary i-ri:loader-2-fill animate-spin text-2xl />
|
|
|
|
<span text-secondary>Loading...</span>
|
2022-11-17 07:35:42 +00:00
|
|
|
</div>
|
2022-11-26 20:41:18 +00:00
|
|
|
<div v-else-if="state === 'done'" p5 text-secondary italic text-center>
|
2022-11-20 20:32:20 +00:00
|
|
|
End of the 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-17 07:35:42 +00:00
|
|
|
ERROR: {{ error }}
|
|
|
|
</div>
|
2022-11-16 16:11:08 +00:00
|
|
|
</div>
|
|
|
|
</template>
|