fix: link to original instance for older unavailable posts (#767)

This commit is contained in:
Ryan Cao 2023-01-04 21:21:03 +08:00 committed by GitHub
parent 6a7633b758
commit 9d5dc1bc3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 5 deletions

View file

@ -2,7 +2,7 @@
// @ts-expect-error missing types // @ts-expect-error missing types
import { DynamicScroller } from 'vue-virtual-scroller' import { DynamicScroller } from 'vue-virtual-scroller'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css' import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
import type { Paginator, WsEvents } from 'masto' import type { Account, Paginator, WsEvents } from 'masto'
const { const {
paginator, paginator,
@ -11,6 +11,7 @@ const {
virtualScroller = false, virtualScroller = false,
eventType = 'update', eventType = 'update',
preprocess, preprocess,
isAccountTimeline,
} = defineProps<{ } = defineProps<{
paginator: Paginator<any, any[]> paginator: Paginator<any, any[]>
keyProp?: string keyProp?: string
@ -18,6 +19,7 @@ const {
stream?: Promise<WsEvents> stream?: Promise<WsEvents>
eventType?: 'notification' | 'update' eventType?: 'notification' | 'update'
preprocess?: (items: any[]) => any[] preprocess?: (items: any[]) => any[]
isAccountTimeline?: boolean
}>() }>()
defineSlots<{ defineSlots<{
@ -34,6 +36,16 @@ defineSlots<{
loading: {} loading: {}
}>() }>()
let account: Account | null = null
const { params } = useRoute()
if (isAccountTimeline) {
const handle = $(computedEager(() => params.account as string))
account = await fetchAccountByHandle(handle)
}
const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream, eventType, preprocess) const { items, prevItems, update, state, endAnchor, error } = usePaginator(paginator, stream, eventType, preprocess)
</script> </script>
@ -72,8 +84,14 @@ const { items, prevItems, update, state, endAnchor, error } = usePaginator(pagin
<slot v-if="state === 'loading'" name="loading"> <slot v-if="state === 'loading'" name="loading">
<TimelineSkeleton /> <TimelineSkeleton />
</slot> </slot>
<div v-else-if="state === 'done'" p5 text-secondary italic text-center> <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') }} {{ $t('common.end_of_list') }}
</template>
</div> </div>
<div v-else-if="state === 'error'" p5 text-secondary> <div v-else-if="state === 'error'" p5 text-secondary>
{{ $t('common.error') }}: {{ error }} {{ $t('common.error') }}: {{ error }}

View file

@ -16,7 +16,7 @@ const virtualScroller = $(computedEager(() => useFeatureFlags().experimentalVirt
</script> </script>
<template> <template>
<CommonPaginator v-bind="{ paginator, stream, preprocess }" :virtual-scroller="virtualScroller"> <CommonPaginator v-bind="{ paginator, stream, preprocess }" :virtual-scroller="virtualScroller" :is-account-timeline="context === 'account'">
<template #updater="{ number, update }"> <template #updater="{ number, update }">
<button py-4 border="b base" flex="~ col" p-3 w-full text-primary font-bold @click="update"> <button py-4 border="b base" flex="~ col" p-3 w-full text-primary font-bold @click="update">
{{ $t('timeline.show_new_items', number, { named: { v: formatNumber(number) } }) }} {{ $t('timeline.show_new_items', number, { named: { v: formatNumber(number) } }) }}

View file

@ -357,7 +357,8 @@
"year_past": "0 years ago|last year|{n} years ago" "year_past": "0 years ago|last year|{n} years ago"
}, },
"timeline": { "timeline": {
"show_new_items": "Show {v} new items|Show {v} new item|Show {v} new items" "show_new_items": "Show {v} new items|Show {v} new item|Show {v} new items",
"view_older_posts": "Older posts from other instances may not be displayed."
}, },
"title": { "title": {
"federated_timeline": "Federated Timeline", "federated_timeline": "Federated Timeline",