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