2022-11-26 02:49:56 +03:00
|
|
|
<script setup lang="ts">
|
2022-11-28 13:23:33 +03:00
|
|
|
import type { Status } from 'masto'
|
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-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)
|
|
|
|
let bottomSpace = $ref(0)
|
2022-11-26 02:49:56 +03:00
|
|
|
|
2022-11-30 20:15:18 +03:00
|
|
|
const { data: status, pending, refresh: refreshStatus } = useAsyncData(`status:${id}`, async () => (
|
2022-11-28 13:23:33 +03:00
|
|
|
window.history.state?.status as Status | undefined)
|
|
|
|
?? await fetchStatus(id),
|
|
|
|
)
|
2022-11-28 14:09:38 +03:00
|
|
|
const { data: context, pending: pendingContext, refresh: refreshContext } = useAsyncData(`context:${id}`, () => useMasto().statuses.fetchContext(id))
|
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
|
|
|
|
|
|
|
|
const statusRect = statusElement.getBoundingClientRect()
|
|
|
|
bottomSpace = window.innerHeight - statusRect.height
|
|
|
|
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
|
|
|
|
|
|
|
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">
|
|
|
|
<div v-if="status" min-h-100vh>
|
|
|
|
<template v-if="context">
|
|
|
|
<template v-for="comment of context?.ancestors" :key="comment.id">
|
|
|
|
<StatusCard :status="comment" border="t base" py3 />
|
|
|
|
</template>
|
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
|
|
|
border="t base"
|
|
|
|
style="scroll-margin-top: 60px"
|
|
|
|
/>
|
|
|
|
<PublishWidget
|
|
|
|
v-if="currentUser"
|
|
|
|
:draft-key="replyDraft!.key"
|
|
|
|
:initial="replyDraft!.draft"
|
|
|
|
border="t base"
|
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
|
|
|
|
2022-11-28 14:09:38 +03:00
|
|
|
<template v-if="context">
|
|
|
|
<template v-for="comment of context?.descendants" :key="comment.id">
|
|
|
|
<StatusCard :status="comment" border="t base" py3 />
|
|
|
|
</template>
|
2022-11-26 02:49:56 +03:00
|
|
|
</template>
|
2022-11-27 03:35:19 +03:00
|
|
|
|
2022-11-28 14:09:38 +03:00
|
|
|
<div border="t base" :style="{ height: `${bottomSpace}px` }" />
|
|
|
|
</div>
|
2022-11-26 02:49:56 +03:00
|
|
|
|
2022-11-28 23:02:44 +03:00
|
|
|
<StatusNotFound v-else :account="$route.params.account" :status="id" />
|
2022-11-28 14:09:38 +03:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<StatusCardSkeleton v-else border="b base" py-3 />
|
2022-11-26 02:49:56 +03:00
|
|
|
</MainContent>
|
|
|
|
</template>
|