diff --git a/src/core.tsx b/src/core.tsx index 4f9e18a..30a8cc4 100644 --- a/src/core.tsx +++ b/src/core.tsx @@ -132,7 +132,13 @@ export function useNostrEvents({ filter: Filter enabled?: boolean }) { - const { isLoading, onConnect, debug, connectedRelays } = useNostr() + const { + isLoading: _isLoadingProvider, + onConnect, + debug, + connectedRelays, + } = useNostr() + const [isLoading, setIsLoading] = useState(_isLoadingProvider) const [events, setEvents] = useState([]) const [unsubscribe, setUnsubscribe] = useState<() => void | void>(() => { return @@ -165,6 +171,8 @@ export function useNostrEvents({ ) const sub = relay.sub([filter]) + setIsLoading(true) + const unsubscribeFunc = () => { _unsubscribe(sub, relay) } @@ -178,8 +186,9 @@ export function useNostrEvents({ return [event, ..._events] }) }) - + sub.on("eose", () => { + setIsLoading(false) onDoneCallback?.() }) diff --git a/src/useProfile.tsx b/src/useProfile.tsx index 1a9e55c..79b87ff 100644 --- a/src/useProfile.tsx +++ b/src/useProfile.tsx @@ -65,7 +65,7 @@ export function useProfile({ pubkey }: { pubkey: string }) { const [fetchedProfiles, setFetchedProfiles] = useAtom(fetchedProfilesAtom) - const { onEvent, onSubscribe } = useNostrEvents({ + const { onEvent, onSubscribe, isLoading } = useNostrEvents({ filter: { kinds: [0], authors: pubkeysToFetch, @@ -103,6 +103,7 @@ export function useProfile({ pubkey }: { pubkey: string }) { const npub = nip19.npubEncode(pubkey) return { + isLoading, data: metadata ? { ...metadata,