1
0
mirror of https://github.com/elk-zone/elk synced 2024-12-12 21:58:05 +09:00
elk/components/common/CommonPaginator.vue

65 lines
1.7 KiB
Vue
Raw Normal View History

2022-11-17 01:11:08 +09:00
<script setup lang="ts">
2022-11-27 15:16:02 +09:00
// @ts-expect-error missing types
import { DynamicScroller } from 'vue-virtual-scroller'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
import type { Paginator, WsEvents } from 'masto'
2022-11-17 01:11:08 +09:00
const { paginator, stream, keyProp = 'id', virtualScroller = false } = defineProps<{
2022-11-17 16:35:42 +09:00
paginator: Paginator<any, any[]>
keyProp?: string
2022-11-28 22:14:27 +09:00
virtualScroller?: boolean
stream?: WsEvents
2022-11-17 01:11:08 +09:00
}>()
2022-11-17 16:35:42 +09:00
2022-11-27 17:54:00 +09:00
defineSlots<{
default: {
item: any
active?: boolean
}
updater: {
number: number
update: () => void
}
2022-11-27 17:54:00 +09:00
loading: {}
}>()
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream)
2022-11-17 01:11:08 +09:00
</script>
<template>
2022-11-17 16:35:42 +09:00
<div>
<slot v-if="prevItems.length" name="updater" v-bind="{ number: prevItems.length, update }" />
<template v-if="virtualScroller">
2022-11-27 22:12:25 +09:00
<DynamicScroller
v-slot="{ item, active }"
:items="items"
:min-item-size="200"
:key-field="keyProp"
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 16:35:42 +09:00
<div ref="endAnchor" />
2022-11-27 14:02:19 +09: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 />
<span text-secondary>Loading...</span>
</div>
</slot>
<div v-else-if="state === 'done'" p5 text-secondary italic text-center>
2022-11-21 05:32:20 +09:00
End of the list
2022-11-17 16:35:42 +09:00
</div>
<div v-else-if="state === 'error'" p5 text-secondary>
2022-11-17 16:35:42 +09:00
ERROR: {{ error }}
</div>
2022-11-17 01:11:08 +09:00
</div>
</template>