Fix threads not loading when navigating directly to them

This commit is contained in:
hzrd149 2023-09-08 15:02:51 -05:00
parent 94cd15663b
commit 81e86c9550
4 changed files with 19 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
"nostrudel": patch
---
Fix threads not loading when navigating directly to them

View File

@ -2,7 +2,7 @@ import { getReferences } from "../helpers/nostr/events";
import { NostrEvent } from "../types/nostr-event";
import { NostrRequest } from "./nostr-request";
import { NostrMultiSubscription } from "./nostr-multi-subscription";
import Subject, { PersistentSubject } from "./subject";
import { PersistentSubject } from "./subject";
export class ThreadLoader {
loading = new PersistentSubject(false);
@ -66,6 +66,12 @@ export class ThreadLoader {
}
}
setRelays(relays: string[]) {
this.relays = relays;
this.subscription.setRelays(relays);
this.loadEvent();
}
private updateSubscription() {
if (this.rootId.value) {
this.subscription.setQuery({ "#e": [this.rootId.value], kinds: [1] });

View File

@ -1,9 +1,11 @@
import { useEffect, useMemo, useRef } from "react";
import { useUnmount } from "react-use";
import { ThreadLoader } from "../classes/thread-loader";
import { linkEvents } from "../helpers/thread";
import { useReadRelayUrls } from "./use-client-relays";
import useSubject from "./use-subject";
import useRelaysChanged from "./use-relays-changed";
type Options = {
enabled?: boolean;
@ -25,6 +27,10 @@ export function useThreadLoader(eventId: string, additionalRelays: string[] = []
else loader.close();
}, [enabled]);
useRelaysChanged(relays, () => {
loader.setRelays(relays);
});
useUnmount(() => {
loader.close();
});

View File

@ -12,7 +12,7 @@ class SingleEventService {
const event = this.eventCache.get(id);
if (event) return event;
this.pending.set(id, this.pending.get(id)?.concat(relays) ?? safeRelayUrls(relays));
this.pending.set(id, this.pending.get(id)?.concat(safeRelayUrls(relays)) ?? safeRelayUrls(relays));
const deferred = createDefer<NostrEvent>();
this.pendingPromises.set(id, deferred);
return deferred;