2022-11-26 08:49:56 +09:00
|
|
|
<script setup lang="ts">
|
2022-11-28 19:23:33 +09:00
|
|
|
import type { Status } from 'masto'
|
2022-11-27 09:35:19 +09:00
|
|
|
import type { ComponentPublicInstance } from 'vue'
|
2022-11-26 08:49:56 +09:00
|
|
|
|
2022-12-01 02:15:18 +09:00
|
|
|
definePageMeta({
|
|
|
|
name: 'status',
|
2022-12-12 08:30:26 +09:00
|
|
|
key: route => route.path,
|
2022-12-01 02:15:18 +09:00
|
|
|
})
|
|
|
|
|
2022-11-26 08:49:56 +09:00
|
|
|
const route = useRoute()
|
2022-11-28 02:34:45 +09:00
|
|
|
const id = $(computedEager(() => route.params.status as string))
|
2022-11-27 09:35:19 +09:00
|
|
|
const main = ref<ComponentPublicInstance | null>(null)
|
|
|
|
let bottomSpace = $ref(0)
|
2022-12-15 01:45:46 +09:00
|
|
|
const publishWidget = ref()
|
2022-11-26 08:49:56 +09:00
|
|
|
|
2022-12-26 23:14:48 +09:00
|
|
|
const { data: status, pending, refresh: refreshStatus } = useAsyncData(
|
|
|
|
`status:${id}`,
|
|
|
|
async () => (window.history.state?.status as Status | undefined) ?? await fetchStatus(id),
|
|
|
|
{ watch: [isMastoInitialised], immediate: isMastoInitialised.value },
|
2022-11-28 19:23:33 +09:00
|
|
|
)
|
2022-12-25 23:04:50 +09:00
|
|
|
const masto = useMasto()
|
|
|
|
const { data: context, pending: pendingContext, refresh: refreshContext } = useAsyncData(`context:${id}`, () => masto.statuses.fetchContext(id))
|
2022-11-27 09:35:19 +09:00
|
|
|
|
2022-11-28 19:23:33 +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
|
|
|
|
|
|
|
|
const statusRect = statusElement.getBoundingClientRect()
|
|
|
|
bottomSpace = window.innerHeight - statusRect.height
|
|
|
|
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()
|
|
|
|
})
|
|
|
|
}
|
2022-11-28 02:34:45 +09:00
|
|
|
|
2022-12-15 01:45:46 +09:00
|
|
|
const focusEditor = () => {
|
|
|
|
publishWidget.value?.focusEditor?.()
|
|
|
|
}
|
|
|
|
|
|
|
|
provide('focus-editor', focusEditor)
|
|
|
|
|
2022-11-28 02:34:45 +09: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 08:49:56 +09:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-11-26 21:58:10 +09:00
|
|
|
<MainContent back>
|
2022-11-28 20:09:38 +09:00
|
|
|
<template v-if="!pending">
|
2022-12-25 21:44:18 +09:00
|
|
|
<div v-if="status" min-h-100vh mt--1px>
|
2022-12-26 16:37:42 +09:00
|
|
|
<template v-for="comment of context?.ancestors" :key="comment.id">
|
|
|
|
<StatusCard
|
|
|
|
:status="comment" :actions="comment.visibility !== 'direct'" context="account"
|
|
|
|
:show-reply-to="false" :connect-reply="true"
|
|
|
|
/>
|
2022-11-26 08:49:56 +09:00
|
|
|
</template>
|
|
|
|
|
2022-11-28 20:09:38 +09:00
|
|
|
<StatusDetails
|
|
|
|
ref="main"
|
|
|
|
:status="status"
|
2022-11-29 17:15:05 +09:00
|
|
|
command
|
2022-11-28 20:09:38 +09:00
|
|
|
style="scroll-margin-top: 60px"
|
2022-12-26 16:37:42 +09:00
|
|
|
:actions="status.visibility !== 'direct'"
|
2022-11-28 20:09:38 +09:00
|
|
|
/>
|
|
|
|
<PublishWidget
|
|
|
|
v-if="currentUser"
|
2022-12-15 01:45:46 +09:00
|
|
|
ref="publishWidget"
|
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
|
|
|
/>
|
2022-11-26 08:49:56 +09:00
|
|
|
|
2022-12-26 16:37:42 +09:00
|
|
|
<template v-for="comment, di of context?.descendants" :key="comment.id">
|
|
|
|
<StatusCard
|
|
|
|
:status="comment" :actions="comment.visibility !== 'direct'" context="account"
|
|
|
|
:connect-reply="comment.id === context?.descendants[di + 1]?.inReplyToId"
|
|
|
|
:show-reply-to="di !== 0 && comment.inReplyToId !== context?.descendants[di - 1]?.id"
|
|
|
|
:class="{ 'border-t border-base': di !== 0 && comment.inReplyToId !== context?.descendants[di - 1]?.id }"
|
|
|
|
/>
|
2022-11-26 08:49:56 +09:00
|
|
|
</template>
|
2022-11-27 09:35:19 +09:00
|
|
|
|
2022-12-26 16:37:42 +09:00
|
|
|
<div :style="{ height: `${bottomSpace}px` }" />
|
2022-11-28 20:09:38 +09:00
|
|
|
</div>
|
2022-11-26 08:49:56 +09:00
|
|
|
|
2022-11-29 05:02:44 +09:00
|
|
|
<StatusNotFound v-else :account="$route.params.account" :status="id" />
|
2022-11-28 20:09:38 +09:00
|
|
|
</template>
|
|
|
|
|
2022-12-06 20:07:17 +09:00
|
|
|
<StatusCardSkeleton v-else border="b base" />
|
2022-11-26 08:49:56 +09:00
|
|
|
</MainContent>
|
|
|
|
</template>
|