perf: improve navigation speed

This commit is contained in:
Anthony Fu 2022-11-24 12:02:18 +08:00
parent 0a8841f4f4
commit 73c35b3c11
4 changed files with 61 additions and 18 deletions

View file

@ -1,19 +1,23 @@
<script setup lang="ts">
import AccountAvatar from '~~/components/account/AccountAvatar.vue'
import type { Component } from 'vue'
const params = useRoute().params
const id = computed(() => params.post as string)
const main = ref<Component | null>(null)
const { data: status } = await useAsyncData(`${id}-status`, () => masto.statuses.fetch(params.post as string))
const { data: context } = await useAsyncData(`${id}-context`, () => masto.statuses.fetchContext(params.post as string))
const { data: status } = await useAsyncData(`status-${id}`, () => masto.statuses.fetch(params.post as string))
const { data: context } = useAsyncData(`context-${id}`, () => masto.statuses.fetchContext(params.post as string))
</script>
<template>
<template v-if="status">
<template v-for="comment of context?.ancestors" :key="comment.id">
<StatusCard :status="comment" border="t base" pt-4 />
<template v-if="context">
<template v-for="comment of context?.ancestors" :key="comment.id">
<StatusCard :status="comment" border="t base" pt-4 />
</template>
</template>
<StatusDetails :status="status" border="t base" pt-4 />
<StatusDetails ref="main" :status="status" border="t base" pt-4 />
<div v-if="currentUser" border="t base" p6 flex gap-4>
<AccountAvatar :account="currentUser.account" w-10 h-10 />
<PublishWidget
@ -24,8 +28,10 @@ const { data: context } = await useAsyncData(`${id}-context`, () => masto.status
/>
</div>
<template v-for="comment of context?.descendants" :key="comment.id">
<StatusCard :status="comment" border="t base" pt-4 />
<template v-if="context">
<template v-for="comment of context?.descendants" :key="comment.id">
<StatusCard :status="comment" border="t base" pt-4 />
</template>
</template>
</template>