From b7614edb70a0d678939d154385af45b29a8de059 Mon Sep 17 00:00:00 2001 From: styppo Date: Tue, 24 Jan 2023 20:19:20 +0000 Subject: [PATCH] Update thread live with new notes --- src/pages/Thread.vue | 52 +++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/src/pages/Thread.vue b/src/pages/Thread.vue index 73ed512..44425f0 100644 --- a/src/pages/Thread.vue +++ b/src/pages/Thread.vue @@ -15,14 +15,14 @@
Loading...
-
+
@@ -55,8 +55,6 @@ export default defineComponent({ }, data() { return { - predecessors: [], - children: [], subId: null, resizeObserver: null, } @@ -87,18 +85,27 @@ export default defineComponent({ return this.root?.id === this.rootId }, ancestors() { - if (!this.rootLoaded) return [] - const root = this.rootId !== this.noteId - ? [this.root] - : [] - return root.concat(this.predecessors) - } + if (!this.noteLoaded) return + const ancestors = this.allAncestors(this.note) + // Sanity check + if (ancestors.length > 0 && ancestors[0].id !== this.rootId) { + console.error(`Invalid thread structure: expected root ${this.rootId} but found ${ancestors[0].id}`) + // return + } + return this.collectPredecessors(ancestors, this.note) + }, + children() { + if (!this.noteLoaded) return + const ancestor = this.note.hasAncestor() + ? this.nostr.getNote(this.note.ancestor()) + : null + return this.collectChildren(this.note, ancestor) + }, }, methods: { startStream() { if (!this.rootId) return this.stream = this.nostr.streamThread(this.rootId) - this.stream.on('init', this.buildThread.bind(this)) }, closeStream() { @@ -107,28 +114,6 @@ export default defineComponent({ this.stream = null }, - buildThread() { - if (!this.noteLoaded) return - const ancestors = this.allAncestors(this.note) - const ancestor = ancestors.length - ? ancestors[ancestors.length - 1] - : null - - // Sanity check - if (ancestors.length > 0 && ancestors[0].id !== this.rootId) { - console.error(`Invalid thread structure: expected root ${this.rootId} but found ${ancestors[0].id}`) - return - } - - this.predecessors = this - .collectPredecessors(ancestors, this.note) - .slice(1) - - this.scrollToMain() - - this.children = this.collectChildren(this.note, ancestor) - }, - collectPredecessors(ancestors, target) { if (!ancestors || !ancestors.length) return [] @@ -224,7 +209,6 @@ export default defineComponent({ }, mounted() { this.startStream() - this.buildThread() this.resizeObserver = new ResizeObserver(this.scrollToMain.bind(this)) this.resizeObserver.observe(this.$refs.ancestors)