mirror of
https://github.com/t4t5/nostr-react.git
synced 2025-09-17 13:18:54 +02:00
Set isLoading based on eose
This commit is contained in:
13
src/core.tsx
13
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<NostrEvent[]>([])
|
||||
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?.()
|
||||
})
|
||||
|
||||
|
@@ -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,
|
||||
|
Reference in New Issue
Block a user