mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-04-09 20:29:17 +02:00
Fix threads not loading when navigating directly to them
This commit is contained in:
parent
94cd15663b
commit
81e86c9550
5
.changeset/stale-meals-report.md
Normal file
5
.changeset/stale-meals-report.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"nostrudel": patch
|
||||
---
|
||||
|
||||
Fix threads not loading when navigating directly to them
|
@ -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] });
|
||||
|
@ -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();
|
||||
});
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user