frontend/pages/[username]/[uuid].vue

54 lines
1.8 KiB
Vue
Raw Normal View History

<template>
<ClientOnly>
2024-05-12 07:26:29 +02:00
<div v-if="loaded" :defer="true" class="mx-auto max-w-2xl w-full pb-72">
<SocialElementsNotesNote v-for="note of context?.ancestors" :note="note" />
<div ref="element" class="first:rounded-t last:rounded-b overflow-hidden">
<SocialElementsNotesNote class="!rounded-none border-2 border-pink-500" v-if="note" :note="note" />
</div>
<SocialElementsNotesNote v-for="note of context?.descendants" :note="note" />
2024-05-12 07:26:29 +02:00
</div>
<div :defer="true" v-else class="mx-auto max-w-2xl w-full overflow-y-auto">
<SocialElementsNotesNote v-for="_ of 5" :skeleton="true" />
2024-05-12 07:26:29 +02:00
</div>
</ClientOnly>
</template>
<script setup lang="ts">
definePageMeta({
layout: "app",
});
const element = ref<HTMLElement | null>(null);
const route = useRoute();
const client = useMegalodon();
const uuid = route.params.uuid as string;
const note = useNote(client, uuid);
const noteId = computed(() => note.value?.id ?? null);
const context = useNoteContext(client, noteId);
const loaded = computed(() => note.value !== null && context.value !== null);
// If ancestors changes, scroll down so that the initial note stays at the same place
watch(
[() => context.value?.ancestors, loaded],
async () => {
if (context.value?.ancestors.length === 0) return;
if (!loaded.value) return;
await nextTick();
// Wait for 200ms
await new Promise((resolve) => setTimeout(resolve, 200));
element.value?.scrollIntoView({
behavior: "smooth",
});
},
{
immediate: true,
},
);
useServerSeoMeta({
title: note.value?.account.display_name,
description: note.value?.content,
ogImage: note.value?.media_attachments[0]?.preview_url,
});
</script>