1
0
elk/pages/[[server]]/@[account]/[status].vue

123 lines
3.4 KiB
Vue
Raw Normal View History

<script setup lang="ts">
// @ts-expect-error missing types
import { DynamicScroller, DynamicScrollerItem } from 'vue-virtual-scroller'
2022-11-27 09:35:19 +09:00
import type { ComponentPublicInstance } from 'vue'
definePageMeta({
name: 'status',
key: route => route.path,
// GoToSocial
alias: ['/:server?/@:account/statuses/:status'],
})
const route = useRoute()
const id = $(computedEager(() => route.params.status as string))
2022-11-27 09:35:19 +09:00
const main = ref<ComponentPublicInstance | null>(null)
const publishWidget = ref()
const { data: status, pending, refresh: refreshStatus } = useAsyncData(
`status:${id}`,
() => fetchStatus(id),
{ watch: [isHydrated], immediate: isHydrated.value, default: () => shallowRef() },
)
2023-01-15 17:38:02 +09:00
const { client } = $(useMasto())
const { data: context, pending: pendingContext, refresh: refreshContext } = useAsyncData(
`context:${id}`,
2023-01-15 17:38:02 +09:00
async () => client.v1.statuses.fetchContext(id),
{ watch: [isHydrated], immediate: isHydrated.value, lazy: true, default: () => shallowRef() },
)
2022-11-27 09:35:19 +09:00
const replyDraft = $computed(() => status.value ? getReplyDraft(status.value) : null)
2022-11-27 09:35:19 +09:00
function scrollTo() {
const statusElement = unrefElement(main)
if (!statusElement)
return
statusElement.scrollIntoView(true)
}
onMounted(scrollTo)
2022-11-28 20:09:38 +09:00
if (pendingContext) {
watchOnce(pendingContext, async () => {
2022-11-27 09:35:19 +09:00
await nextTick()
scrollTo()
})
}
const focusEditor = () => {
publishWidget.value?.focusEditor?.()
}
provide('focus-editor', focusEditor)
watch(publishWidget, () => {
if (window.history.state.focusReply)
focusEditor()
})
onReactivated(() => {
// Silently update data when reentering the page
// The user will see the previous content first, and any changes will be updated to the UI when the request is completed
refreshStatus()
refreshContext()
})
</script>
<template>
2022-11-26 21:58:10 +09:00
<MainContent back>
2023-01-19 00:59:37 +09:00
<template v-if="!pending && !pendingContext">
2023-01-05 21:35:08 +09:00
<div v-if="status" xl:mt-4 border="b base" mb="50vh">
2023-01-19 00:59:37 +09:00
<template v-for="comment, i of context?.ancestors" :key="comment.id">
2022-12-26 16:37:42 +09:00
<StatusCard
:status="comment" :actions="comment.visibility !== 'direct'" context="account"
2023-01-19 00:59:37 +09:00
:has-older="true" :newer="context?.ancestors[i - 1]"
2022-12-26 16:37:42 +09:00
/>
</template>
2022-11-28 20:09:38 +09:00
<StatusDetails
ref="main"
:status="status"
2023-01-19 00:59:37 +09:00
:newer="context?.ancestors.at(-1)"
command
2022-11-28 20:09:38 +09:00
style="scroll-margin-top: 60px"
/>
<PublishWidget
v-if="currentUser"
ref="publishWidget"
border="y base"
2022-11-28 20:09:38 +09:00
:draft-key="replyDraft!.key"
:initial="replyDraft!.draft"
2022-12-01 16:24:35 +09:00
@published="refreshContext()"
2022-11-28 20:09:38 +09:00
/>
<TimelineSkeleton v-if="pendingContext" />
<DynamicScroller
v-slot="{ item, index, active }"
:items="context?.descendants || []"
:min-item-size="200"
key-field="id"
page-mode
>
<DynamicScrollerItem :item="item" :active="active">
<StatusCard
:status="item"
context="account"
:older="context?.descendants[index + 1]"
2023-01-19 00:59:37 +09:00
:newer="index > 0 ? context?.descendants[index - 1] : status"
:has-newer="index === 0"
:main="status"
/>
</DynamicScrollerItem>
</DynamicScroller>
2022-11-28 20:09:38 +09:00
</div>
2023-01-06 01:48:20 +09:00
<StatusNotFound v-else :account="route.params.account as string" :status="id" />
2022-11-28 20:09:38 +09:00
</template>
<StatusCardSkeleton v-else border="b base" />
</MainContent>
</template>