2022-11-16 17:11:08 +01:00
|
|
|
<script setup lang="ts">
|
2022-11-27 07:16:02 +01:00
|
|
|
// @ts-expect-error missing types
|
2022-11-26 20:57:59 +01:00
|
|
|
import { DynamicScroller } from 'vue-virtual-scroller'
|
|
|
|
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
|
2023-01-04 14:21:03 +01:00
|
|
|
import type { Account, Paginator, WsEvents } from 'masto'
|
2022-11-16 17:11:08 +01:00
|
|
|
|
2022-12-27 23:18:16 +01:00
|
|
|
const {
|
|
|
|
paginator,
|
|
|
|
stream,
|
|
|
|
keyProp = 'id',
|
|
|
|
virtualScroller = false,
|
|
|
|
eventType = 'update',
|
|
|
|
preprocess,
|
2023-01-04 14:21:03 +01:00
|
|
|
isAccountTimeline,
|
2022-12-27 23:18:16 +01:00
|
|
|
} = defineProps<{
|
2022-11-17 08:35:42 +01:00
|
|
|
paginator: Paginator<any, any[]>
|
|
|
|
keyProp?: string
|
2022-11-28 14:14:27 +01:00
|
|
|
virtualScroller?: boolean
|
2022-12-28 22:43:46 +01:00
|
|
|
stream?: Promise<WsEvents>
|
2022-12-02 03:21:10 +01:00
|
|
|
eventType?: 'notification' | 'update'
|
2022-12-27 18:47:05 +01:00
|
|
|
preprocess?: (items: any[]) => any[]
|
2023-01-04 14:21:03 +01:00
|
|
|
isAccountTimeline?: boolean
|
2022-11-16 17:11:08 +01:00
|
|
|
}>()
|
2022-11-17 08:35:42 +01:00
|
|
|
|
2022-11-27 09:54:00 +01:00
|
|
|
defineSlots<{
|
|
|
|
default: {
|
|
|
|
item: any
|
|
|
|
active?: boolean
|
2022-12-27 18:47:05 +01:00
|
|
|
older?: any
|
2022-12-28 00:25:41 +01:00
|
|
|
newer?: any // newer is undefined when index === 0
|
2022-11-27 09:54:00 +01:00
|
|
|
}
|
2022-11-28 12:18:45 +01:00
|
|
|
updater: {
|
|
|
|
number: number
|
|
|
|
update: () => void
|
|
|
|
}
|
2022-11-27 09:54:00 +01:00
|
|
|
loading: {}
|
|
|
|
}>()
|
|
|
|
|
2023-01-04 14:21:03 +01:00
|
|
|
let account: Account | null = null
|
|
|
|
|
|
|
|
const { params } = useRoute()
|
|
|
|
|
|
|
|
if (isAccountTimeline) {
|
|
|
|
const handle = $(computedEager(() => params.account as string))
|
|
|
|
|
|
|
|
account = await fetchAccountByHandle(handle)
|
|
|
|
}
|
|
|
|
|
2022-12-27 18:47:05 +01:00
|
|
|
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream, eventType, preprocess)
|
2022-11-16 17:11:08 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-17 08:35:42 +01:00
|
|
|
<div>
|
2022-11-28 12:18:45 +01:00
|
|
|
<slot v-if="prevItems.length" name="updater" v-bind="{ number: prevItems.length, update }" />
|
2022-11-30 01:47:54 +01:00
|
|
|
<slot name="items" :items="items">
|
|
|
|
<template v-if="virtualScroller">
|
|
|
|
<DynamicScroller
|
2022-12-27 23:18:16 +01:00
|
|
|
v-slot="{ item, active, index }"
|
2022-11-30 01:47:54 +01:00
|
|
|
:items="items"
|
|
|
|
:min-item-size="200"
|
|
|
|
:key-field="keyProp"
|
|
|
|
page-mode
|
|
|
|
>
|
2022-12-27 23:18:16 +01:00
|
|
|
<slot
|
2022-12-29 14:55:09 +01:00
|
|
|
:key="item[keyProp]"
|
2022-12-27 23:18:16 +01:00
|
|
|
:item="item"
|
|
|
|
:active="active"
|
2022-12-28 00:25:41 +01:00
|
|
|
:older="items[index + 1]"
|
|
|
|
:newer="items[index - 1]"
|
2022-12-27 23:18:16 +01:00
|
|
|
/>
|
2022-11-30 01:47:54 +01:00
|
|
|
</DynamicScroller>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<slot
|
2022-12-28 00:25:41 +01:00
|
|
|
v-for="item, index of items"
|
2022-11-30 01:47:54 +01:00
|
|
|
:key="item[keyProp]"
|
|
|
|
:item="item"
|
2022-12-28 00:25:41 +01:00
|
|
|
:older="items[index + 1]"
|
|
|
|
:newer="items[index - 1]"
|
2022-11-30 01:47:54 +01:00
|
|
|
/>
|
|
|
|
</template>
|
|
|
|
</slot>
|
2022-11-17 08:35:42 +01:00
|
|
|
<div ref="endAnchor" />
|
2022-11-27 06:02:19 +01:00
|
|
|
<slot v-if="state === 'loading'" name="loading">
|
2022-12-30 16:34:23 +01:00
|
|
|
<TimelineSkeleton />
|
2022-11-27 06:02:19 +01:00
|
|
|
</slot>
|
2023-01-04 14:21:03 +01:00
|
|
|
<div v-else-if="state === 'done'" p5 text-secondary italic text-center flex flex-col items-center gap1>
|
|
|
|
<template v-if="isAccountTimeline">
|
|
|
|
<span>{{ $t('timeline.view_older_posts') }}</span>
|
|
|
|
<a :href="account!.url" not-italic text-primary hover="underline text-primary-active">{{ $t('menu.open_in_original_site') }}</a>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
{{ $t('common.end_of_list') }}
|
|
|
|
</template>
|
2022-11-17 08:35:42 +01:00
|
|
|
</div>
|
2022-11-26 21:41:18 +01:00
|
|
|
<div v-else-if="state === 'error'" p5 text-secondary>
|
2022-11-29 11:55:28 +01:00
|
|
|
{{ $t('common.error') }}: {{ error }}
|
2022-11-17 08:35:42 +01:00
|
|
|
</div>
|
2022-11-16 17:11:08 +01:00
|
|
|
</div>
|
|
|
|
</template>
|