2022-11-26 02:49:56 +03:00
|
|
|
<script setup lang="ts">
|
2023-01-16 03:33:07 +03:00
|
|
|
// @ts-expect-error missing types
|
|
|
|
import { DynamicScroller, DynamicScrollerItem } from 'vue-virtual-scroller'
|
2022-11-27 03:35:19 +03:00
|
|
|
import type { ComponentPublicInstance } from 'vue'
|
2022-11-26 02:49:56 +03:00
|
|
|
|
2022-11-30 20:15:18 +03:00
|
|
|
definePageMeta({
|
|
|
|
name: 'status',
|
2022-12-12 02:30:26 +03:00
|
|
|
key: route => route.path,
|
2023-01-15 12:55:58 +03:00
|
|
|
// GoToSocial
|
2023-01-15 22:09:01 +03:00
|
|
|
alias: ['/:server?/@:account/statuses/:status'],
|
2022-11-30 20:15:18 +03:00
|
|
|
})
|
|
|
|
|
2022-11-26 02:49:56 +03:00
|
|
|
const route = useRoute()
|
2022-11-27 20:34:45 +03:00
|
|
|
const id = $(computedEager(() => route.params.status as string))
|
2022-11-27 03:35:19 +03:00
|
|
|
const main = ref<ComponentPublicInstance | null>(null)
|
2022-12-30 19:38:46 +03:00
|
|
|
|
2022-12-14 19:45:46 +03:00
|
|
|
const publishWidget = ref()
|
2022-11-26 02:49:56 +03:00
|
|
|
|
2022-12-26 17:14:48 +03:00
|
|
|
const { data: status, pending, refresh: refreshStatus } = useAsyncData(
|
|
|
|
`status:${id}`,
|
2023-01-02 03:00:13 +03:00
|
|
|
() => fetchStatus(id),
|
2023-01-16 03:33:07 +03:00
|
|
|
{ watch: [isHydrated], immediate: isHydrated.value, default: () => shallowRef() },
|
2022-11-28 13:23:33 +03:00
|
|
|
)
|
2023-01-15 11:38:02 +03:00
|
|
|
const { client } = $(useMasto())
|
2023-01-04 22:55:57 +03:00
|
|
|
const { data: context, pending: pendingContext, refresh: refreshContext } = useAsyncData(
|
|
|
|
`context:${id}`,
|
2023-01-15 11:38:02 +03:00
|
|
|
async () => client.v1.statuses.fetchContext(id),
|
2023-01-16 03:33:07 +03:00
|
|
|
{ watch: [isHydrated], immediate: isHydrated.value, lazy: true, default: () => shallowRef() },
|
2023-01-04 22:55:57 +03:00
|
|
|
)
|
2022-11-27 03:35:19 +03:00
|
|
|
|
2022-11-28 13:23:33 +03:00
|
|
|
const replyDraft = $computed(() => status.value ? getReplyDraft(status.value) : null)
|
|
|
|
|
2022-11-27 03:35:19 +03:00
|
|
|
function scrollTo() {
|
|
|
|
const statusElement = unrefElement(main)
|
|
|
|
if (!statusElement)
|
|
|
|
return
|
|
|
|
|
|
|
|
statusElement.scrollIntoView(true)
|
|
|
|
}
|
|
|
|
|
|
|
|
onMounted(scrollTo)
|
|
|
|
|
2022-11-28 14:09:38 +03:00
|
|
|
if (pendingContext) {
|
|
|
|
watchOnce(pendingContext, async () => {
|
2022-11-27 03:35:19 +03:00
|
|
|
await nextTick()
|
|
|
|
scrollTo()
|
|
|
|
})
|
|
|
|
}
|
2022-11-27 20:34:45 +03:00
|
|
|
|
2022-12-14 19:45:46 +03:00
|
|
|
const focusEditor = () => {
|
|
|
|
publishWidget.value?.focusEditor?.()
|
|
|
|
}
|
|
|
|
|
|
|
|
provide('focus-editor', focusEditor)
|
|
|
|
|
2023-01-07 10:55:07 +03:00
|
|
|
watch(publishWidget, () => {
|
|
|
|
if (window.history.state.focusReply)
|
|
|
|
focusEditor()
|
|
|
|
})
|
|
|
|
|
2022-11-27 20:34:45 +03:00
|
|
|
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()
|
|
|
|
})
|
2022-11-26 02:49:56 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-26 15:58:10 +03:00
|
|
|
<MainContent back>
|
2022-11-28 14:09:38 +03:00
|
|
|
<template v-if="!pending">
|
2023-01-05 15:35:08 +03:00
|
|
|
<div v-if="status" xl:mt-4 border="b base" mb="50vh">
|
2022-12-26 10:37:42 +03:00
|
|
|
<template v-for="comment of context?.ancestors" :key="comment.id">
|
|
|
|
<StatusCard
|
|
|
|
:status="comment" :actions="comment.visibility !== 'direct'" context="account"
|
2022-12-28 02:25:41 +03:00
|
|
|
:has-older="true" :has-newer="true"
|
2022-12-26 10:37:42 +03:00
|
|
|
/>
|
2022-11-26 02:49:56 +03:00
|
|
|
</template>
|
|
|
|
|
2022-11-28 14:09:38 +03:00
|
|
|
<StatusDetails
|
|
|
|
ref="main"
|
|
|
|
:status="status"
|
2022-11-29 11:15:05 +03:00
|
|
|
command
|
2022-11-28 14:09:38 +03:00
|
|
|
style="scroll-margin-top: 60px"
|
|
|
|
/>
|
|
|
|
<PublishWidget
|
|
|
|
v-if="currentUser"
|
2022-12-14 19:45:46 +03:00
|
|
|
ref="publishWidget"
|
2022-12-27 21:10:03 +03:00
|
|
|
border="y base"
|
2022-11-28 14:09:38 +03:00
|
|
|
:draft-key="replyDraft!.key"
|
|
|
|
:initial="replyDraft!.draft"
|
2022-12-01 10:24:35 +03:00
|
|
|
@published="refreshContext()"
|
2022-11-28 14:09:38 +03:00
|
|
|
/>
|
2022-11-26 02:49:56 +03:00
|
|
|
|
2023-01-16 03:33:07 +03: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]"
|
|
|
|
:newer="context?.descendants[index - 1]"
|
|
|
|
:has-newer="index === 0"
|
|
|
|
:main="status"
|
|
|
|
/>
|
|
|
|
</DynamicScrollerItem>
|
|
|
|
</DynamicScroller>
|
2022-11-28 14:09:38 +03:00
|
|
|
</div>
|
2022-11-26 02:49:56 +03:00
|
|
|
|
2023-01-05 19:48:20 +03:00
|
|
|
<StatusNotFound v-else :account="route.params.account as string" :status="id" />
|
2022-11-28 14:09:38 +03:00
|
|
|
</template>
|
|
|
|
|
2022-12-06 14:07:17 +03:00
|
|
|
<StatusCardSkeleton v-else border="b base" />
|
2022-11-26 02:49:56 +03:00
|
|
|
</MainContent>
|
|
|
|
</template>
|