From 68d8a0085c6340d8c5bb0a1a9cefec49e33cd8d7 Mon Sep 17 00:00:00 2001 From: buttercat1791 Date: Sat, 10 May 2025 10:56:55 -0500 Subject: [PATCH] Ensure an alert is shown when publication sections are missing --- src/lib/components/Publication.svelte | 12 +----------- src/lib/components/PublicationSection.svelte | 2 +- src/lib/data_structures/publication_tree.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/lib/components/Publication.svelte b/src/lib/components/Publication.svelte index 8868a47..3ec008d 100644 --- a/src/lib/components/Publication.svelte +++ b/src/lib/components/Publication.svelte @@ -29,7 +29,7 @@ // TODO: Test load handling. - let leaves = $state([]); + let leaves = $state>([]); let isLoading = $state(false); let isDone = $state(false); let lastElementRef = $state(null); @@ -48,16 +48,6 @@ break; } - if (value == null) { - isLoading = false; - break; - } - - if (leaves.includes(value)) { - isLoading = false; - break; - } - leaves.push(value); } diff --git a/src/lib/components/PublicationSection.svelte b/src/lib/components/PublicationSection.svelte index 7e14a97..e9829c9 100644 --- a/src/lib/components/PublicationSection.svelte +++ b/src/lib/components/PublicationSection.svelte @@ -14,7 +14,7 @@ }: { address: string, rootAddress: string, - leaves: NDKEvent[], + leaves: Array, ref: (ref: HTMLElement) => void, } = $props(); diff --git a/src/lib/data_structures/publication_tree.ts b/src/lib/data_structures/publication_tree.ts index 3f61aed..d616740 100644 --- a/src/lib/data_structures/publication_tree.ts +++ b/src/lib/data_structures/publication_tree.ts @@ -345,11 +345,19 @@ export class PublicationTree implements AsyncIterable { continue; } + if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) { + return { done: false, value: null }; + } + const event = await this.getEvent(this.#cursor.target!.address); return { done: false, value: event }; } } while (this.#cursor.tryMoveToParent()); + if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) { + return { done: false, value: null }; + } + // If we get to this point, we're at the root node (can't move up any more). return { done: true, value: null }; } @@ -370,11 +378,19 @@ export class PublicationTree implements AsyncIterable { continue; } + if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) { + return { done: false, value: null }; + } + const event = await this.getEvent(this.#cursor.target!.address); return { done: false, value: event }; } } while (this.#cursor.tryMoveToParent()); + if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) { + return { done: false, value: null }; + } + return { done: true, value: null }; }