From ff070ea9da7605f1d3f83bdb91ab96139aecd579 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Horv=C3=A1th=20B=C3=A1lint?= <40771359+horvbalint@users.noreply.github.com> Date: Fri, 17 Feb 2023 23:11:35 +0100 Subject: [PATCH] fix: better loading handling on status page (#1729) Co-authored-by: Michel EDIGHOFFER --- pages/[[server]]/@[account]/[status].vue | 119 ++++++++++++----------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/pages/[[server]]/@[account]/[status].vue b/pages/[[server]]/@[account]/[status].vue index 7d23b4ea2a..4ebe72c5f1 100644 --- a/pages/[[server]]/@[account]/[status].vue +++ b/pages/[[server]]/@[account]/[status].vue @@ -14,8 +14,6 @@ const route = useRoute() const id = $(computedEager(() => route.params.status as string)) const main = ref(null) -const publishWidget = ref() - const { data: status, pending, refresh: refreshStatus } = useAsyncData( `status:${id}`, () => fetchStatus(id), @@ -28,9 +26,15 @@ const { data: context, pending: pendingContext, refresh: refreshContext } = useA { watch: [isHydrated], immediate: isHydrated.value, lazy: true, default: () => shallowRef() }, ) -const replyDraft = $computed(() => status.value ? getReplyDraft(status.value) : null) +if (pendingContext) + watchOnce(pendingContext, scrollTo) + +if (pending) + watchOnce(pending, scrollTo) + +async function scrollTo() { + await nextTick() -function scrollTo() { const statusElement = unrefElement(main) if (!statusElement) return @@ -38,18 +42,8 @@ function scrollTo() { statusElement.scrollIntoView(true) } -onMounted(scrollTo) - -if (pendingContext) { - watchOnce(pendingContext, async () => { - await nextTick() - scrollTo() - }) -} - -const focusEditor = () => { - publishWidget.value?.focusEditor?.() -} +const publishWidget = ref() +const focusEditor = () => publishWidget.value?.focusEditor?.() provide('focus-editor', focusEditor) @@ -58,6 +52,8 @@ watch(publishWidget, () => { focusEditor() }) +const replyDraft = $computed(() => status.value ? getReplyDraft(status.value) : null) + 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 @@ -68,55 +64,60 @@ onReactivated(() => {