From e578fa3318bb3fb2158b1135ca44c13121f9a6f6 Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Mon, 4 Nov 2024 23:55:02 +0100 Subject: [PATCH] refactor: :sparkles: Add threaded view to Notes --- components/social-elements/notes/header.vue | 4 +- components/social-elements/notes/note.vue | 72 +++++++++++++++------ composables/Note.ts | 20 ++++-- pages/[username]/[uuid].vue | 6 +- 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/components/social-elements/notes/header.vue b/components/social-elements/notes/header.vue index a4d5d09..dc4d7d8 100644 --- a/components/social-elements/notes/header.vue +++ b/components/social-elements/notes/header.vue @@ -20,7 +20,7 @@ -
+
Account profile -
+
diff --git a/components/social-elements/notes/note.vue b/components/social-elements/notes/note.vue index 7f008ea..99a6314 100644 --- a/components/social-elements/notes/note.vue +++ b/components/social-elements/notes/note.vue @@ -1,24 +1,41 @@ @@ -29,17 +46,27 @@ import Skeleton from "~/components/skeleton/Skeleton.vue"; import Header from "./header.vue"; import InteractionRow from "./interactions/row.vue"; import NoteContent from "./note-content.vue"; -import ReplyHeader from "./reply-header.vue"; const props = withDefaults( defineProps<{ - element?: Status; + element?: MaybeRef; small?: boolean; disabled?: boolean; showInteractions?: boolean; + threadView?: boolean; + threadViewTop?: boolean; + renderReplies?: boolean; + padding?: boolean; + borders?: boolean; + background?: boolean; }>(), { showInteractions: true, + padding: true, + borders: true, + renderReplies: true, + background: true, + threadViewTop: true, }, ); @@ -63,4 +90,9 @@ const { isReply, reblogDisplayName, } = useNoteData(noteRef, client, settings); + +const inReplyToId = computed( + () => outputtedNote?.value?.in_reply_to_id ?? null, +); +const reply = useNote(client, inReplyToId); \ No newline at end of file diff --git a/composables/Note.ts b/composables/Note.ts index c5ab14a..d6b5dcd 100644 --- a/composables/Note.ts +++ b/composables/Note.ts @@ -1,18 +1,24 @@ import type { Client } from "@versia/client"; import type { Status } from "@versia/client/types"; -export const useNote = (client: MaybeRef, noteId: string) => { - if (!ref(client).value) { +export const useNote = ( + client: MaybeRef, + noteId: MaybeRef, +) => { + if (!(toValue(client) && toValue(noteId))) { return ref(null as Status | null); } const output = ref(null as Status | null); - ref(client) - .value?.getStatus(noteId) - .then((res) => { - output.value = res.data; - }); + watchEffect(() => { + toValue(noteId) && + toValue(client) + ?.getStatus(toValue(noteId) as string) + .then((res) => { + output.value = res.data; + }); + }); return output; }; diff --git a/pages/[username]/[uuid].vue b/pages/[username]/[uuid].vue index 60a5ccc..8d89906 100644 --- a/pages/[username]/[uuid].vue +++ b/pages/[username]/[uuid].vue @@ -1,10 +1,10 @@