elk/components/common/CommonPaginator.vue

31 lines
667 B
Vue
Raw Normal View History

2022-11-16 17:11:08 +01:00
<script setup lang="ts">
2022-11-17 08:35:42 +01:00
import type { Paginator } from 'masto'
2022-11-16 17:11:08 +01:00
2022-11-17 08:35:42 +01:00
const { paginator, keyProp = 'id' } = defineProps<{
paginator: Paginator<any, any[]>
keyProp?: string
2022-11-16 17:11:08 +01:00
}>()
2022-11-17 08:35:42 +01:00
const { items, state, endAnchor, error } = usePaginator(paginator)
2022-11-16 17:11:08 +01:00
</script>
<template>
2022-11-17 08:35:42 +01:00
<div>
<slot
v-for="item of items"
:key="item[keyProp]"
:item="item"
/>
<div ref="endAnchor" />
<div v-if="state === 'loading'" p5 color-gray-5>
Loading...
</div>
<div v-else-if="state === 'done'" p5 color-gray>
End of list
</div>
<div v-else-if="state === 'error'" p5 color-gray>
ERROR: {{ error }}
</div>
2022-11-16 17:11:08 +01:00
</div>
</template>