2023-01-09 12:23:15 +00:00
|
|
|
<script setup lang="ts" generic="T, O, U = T">
|
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'
|
2023-01-06 18:50:31 +00:00
|
|
|
import type { Paginator, WsEvents } from 'masto'
|
2022-11-16 16:11:08 +00:00
|
|
|
|
2022-12-27 22:18:16 +00:00
|
|
|
const {
|
|
|
|
paginator,
|
|
|
|
stream,
|
|
|
|
keyProp = 'id',
|
|
|
|
virtualScroller = false,
|
|
|
|
eventType = 'update',
|
|
|
|
preprocess,
|
|
|
|
} = defineProps<{
|
2023-01-08 07:49:32 +00:00
|
|
|
paginator: Paginator<T[], O>
|
|
|
|
keyProp?: keyof T
|
2022-11-28 13:14:27 +00:00
|
|
|
virtualScroller?: boolean
|
2022-12-28 21:43:46 +00:00
|
|
|
stream?: Promise<WsEvents>
|
2022-12-02 02:21:10 +00:00
|
|
|
eventType?: 'notification' | 'update'
|
2023-01-09 15:39:59 +00:00
|
|
|
preprocess?: (items: (U | T)[]) => U[]
|
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: {
|
2023-01-09 12:23:15 +00:00
|
|
|
items: U[]
|
|
|
|
item: U
|
2023-01-08 08:51:45 +00:00
|
|
|
index: number
|
2022-11-27 08:54:00 +00:00
|
|
|
active?: boolean
|
2023-01-09 12:23:15 +00:00
|
|
|
older?: U
|
|
|
|
newer?: U // newer is undefined when index === 0
|
2023-01-08 07:49:32 +00:00
|
|
|
}
|
|
|
|
items: {
|
2023-01-09 12:23:15 +00:00
|
|
|
items: U[]
|
2022-11-27 08:54:00 +00:00
|
|
|
}
|
2022-11-28 11:18:45 +00:00
|
|
|
updater: {
|
|
|
|
number: number
|
|
|
|
update: () => void
|
|
|
|
}
|
2022-11-27 08:54:00 +00:00
|
|
|
loading: {}
|
2023-01-06 18:29:44 +00:00
|
|
|
done: {}
|
2022-11-27 08:54:00 +00:00
|
|
|
}>()
|
|
|
|
|
2023-01-08 07:49:32 +00:00
|
|
|
const { t } = useI18n()
|
|
|
|
|
2023-01-15 08:38:02 +00:00
|
|
|
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, $$(stream), eventType, preprocess)
|
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-30 00:47:54 +00:00
|
|
|
<slot name="items" :items="items">
|
|
|
|
<template v-if="virtualScroller">
|
|
|
|
<DynamicScroller
|
2022-12-27 22:18:16 +00:00
|
|
|
v-slot="{ item, active, index }"
|
2022-11-30 00:47:54 +00:00
|
|
|
:items="items"
|
|
|
|
:min-item-size="200"
|
|
|
|
:key-field="keyProp"
|
|
|
|
page-mode
|
|
|
|
>
|
2022-12-27 22:18:16 +00:00
|
|
|
<slot
|
2022-12-29 13:55:09 +00:00
|
|
|
:key="item[keyProp]"
|
2022-12-27 22:18:16 +00:00
|
|
|
:item="item"
|
|
|
|
:active="active"
|
2022-12-27 23:25:41 +00:00
|
|
|
:older="items[index + 1]"
|
|
|
|
:newer="items[index - 1]"
|
2023-01-08 08:51:45 +00:00
|
|
|
:index="index"
|
|
|
|
:items="items"
|
2022-12-27 22:18:16 +00:00
|
|
|
/>
|
2022-11-30 00:47:54 +00:00
|
|
|
</DynamicScroller>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<slot
|
2022-12-27 23:25:41 +00:00
|
|
|
v-for="item, index of items"
|
2023-01-08 07:49:32 +00:00
|
|
|
:key="(item as any)[keyProp]"
|
2022-11-30 00:47:54 +00:00
|
|
|
:item="item"
|
2022-12-27 23:25:41 +00:00
|
|
|
:older="items[index + 1]"
|
|
|
|
:newer="items[index - 1]"
|
2023-01-08 08:51:45 +00:00
|
|
|
:index="index"
|
|
|
|
:items="items"
|
2022-11-30 00:47:54 +00:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</slot>
|
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">
|
2022-12-30 15:34:23 +00:00
|
|
|
<TimelineSkeleton />
|
2022-11-27 05:02:19 +00:00
|
|
|
</slot>
|
2023-01-06 18:29:44 +00:00
|
|
|
<slot v-else-if="state === 'done'" name="done">
|
|
|
|
<div p5 text-secondary italic text-center>
|
2023-01-08 07:49:32 +00:00
|
|
|
{{ t('common.end_of_list') }}
|
2023-01-06 18:29:44 +00:00
|
|
|
</div>
|
|
|
|
</slot>
|
2022-11-26 20:41:18 +00:00
|
|
|
<div v-else-if="state === 'error'" p5 text-secondary>
|
2023-01-08 07:49:32 +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>
|