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
|
filter: Filter
|
||||||
enabled?: boolean
|
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 [events, setEvents] = useState<NostrEvent[]>([])
|
||||||
const [unsubscribe, setUnsubscribe] = useState<() => void | void>(() => {
|
const [unsubscribe, setUnsubscribe] = useState<() => void | void>(() => {
|
||||||
return
|
return
|
||||||
@@ -165,6 +171,8 @@ export function useNostrEvents({
|
|||||||
)
|
)
|
||||||
const sub = relay.sub([filter])
|
const sub = relay.sub([filter])
|
||||||
|
|
||||||
|
setIsLoading(true)
|
||||||
|
|
||||||
const unsubscribeFunc = () => {
|
const unsubscribeFunc = () => {
|
||||||
_unsubscribe(sub, relay)
|
_unsubscribe(sub, relay)
|
||||||
}
|
}
|
||||||
@@ -178,8 +186,9 @@ export function useNostrEvents({
|
|||||||
return [event, ..._events]
|
return [event, ..._events]
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
sub.on("eose", () => {
|
sub.on("eose", () => {
|
||||||
|
setIsLoading(false)
|
||||||
onDoneCallback?.()
|
onDoneCallback?.()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@@ -65,7 +65,7 @@ export function useProfile({ pubkey }: { pubkey: string }) {
|
|||||||
|
|
||||||
const [fetchedProfiles, setFetchedProfiles] = useAtom(fetchedProfilesAtom)
|
const [fetchedProfiles, setFetchedProfiles] = useAtom(fetchedProfilesAtom)
|
||||||
|
|
||||||
const { onEvent, onSubscribe } = useNostrEvents({
|
const { onEvent, onSubscribe, isLoading } = useNostrEvents({
|
||||||
filter: {
|
filter: {
|
||||||
kinds: [0],
|
kinds: [0],
|
||||||
authors: pubkeysToFetch,
|
authors: pubkeysToFetch,
|
||||||
@@ -103,6 +103,7 @@ export function useProfile({ pubkey }: { pubkey: string }) {
|
|||||||
const npub = nip19.npubEncode(pubkey)
|
const npub = nip19.npubEncode(pubkey)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
isLoading,
|
||||||
data: metadata
|
data: metadata
|
||||||
? {
|
? {
|
||||||
...metadata,
|
...metadata,
|
||||||
|
Reference in New Issue
Block a user