Browse Source

ToC corrections

master
silberengel 8 months ago
parent
commit
c7ce636210
  1. 4
      src/app.css
  2. 19
      src/lib/data_structures/publication_tree.ts

4
src/app.css

@ -506,11 +506,11 @@ @@ -506,11 +506,11 @@
/* Table of Contents highlighting */
.toc-highlight {
@apply bg-primary-100 dark:bg-primary-800 border-l-4 border-primary-600 dark:border-primary-400;
@apply bg-primary-200 dark:bg-primary-700 border-l-4 border-primary-600 dark:border-primary-400 font-medium;
transition: all 0.2s ease-in-out;
}
.toc-highlight:hover {
@apply bg-primary-200 dark:bg-primary-700;
@apply bg-primary-300 dark:bg-primary-600;
}
}

19
src/lib/data_structures/publication_tree.ts

@ -246,8 +246,11 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> { @@ -246,8 +246,11 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> {
async tryMoveTo(address?: string) {
if (!address) {
const startEvent = await this.#tree.#depthFirstRetrieve();
if (!startEvent) {
return false;
}
this.target = await this.#tree.#nodes
.get(startEvent!.tagAddress())
.get(startEvent.tagAddress())
?.value();
} else {
this.target = await this.#tree.#nodes.get(address)?.value();
@ -424,8 +427,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> { @@ -424,8 +427,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> {
): Promise<IteratorResult<NDKEvent | null>> {
if (!this.#cursor.target) {
if (await this.#cursor.tryMoveTo(this.#bookmark)) {
const event = await this.getEvent(this.#cursor.target!.address);
return { done: false, value: event };
return this.#yieldEventAtCursor(false);
}
}
@ -440,7 +442,10 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> { @@ -440,7 +442,10 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> {
async #yieldEventAtCursor(
done: boolean,
): Promise<IteratorResult<NDKEvent | null>> {
const value = (await this.getEvent(this.#cursor.target!.address)) ?? null;
if (!this.#cursor.target) {
return { done, value: null };
}
const value = (await this.getEvent(this.#cursor.target.address)) ?? null;
return { done, value };
}
@ -471,7 +476,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> { @@ -471,7 +476,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> {
continue;
}
if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) {
if (this.#cursor.target && this.#cursor.target.status === PublicationTreeNodeStatus.Error) {
return { done: false, value: null };
}
@ -479,7 +484,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> { @@ -479,7 +484,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> {
}
} while (this.#cursor.tryMoveToParent());
if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) {
if (this.#cursor.target && this.#cursor.target.status === PublicationTreeNodeStatus.Error) {
return { done: false, value: null };
}
@ -518,7 +523,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> { @@ -518,7 +523,7 @@ export class PublicationTree implements AsyncIterable<NDKEvent | null> {
}
} while (this.#cursor.tryMoveToParent());
if (this.#cursor.target!.status === PublicationTreeNodeStatus.Error) {
if (this.#cursor.target && this.#cursor.target.status === PublicationTreeNodeStatus.Error) {
return { done: false, value: null };
}

Loading…
Cancel
Save