Set isLoading based on eose

This commit is contained in:
Tristan Edwards
2023-01-29 19:06:13 +00:00
parent af1dd50597
commit 76a8461392
2 changed files with 13 additions and 3 deletions

View File

@@ -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?.()
})

View File

@@ -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,