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 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)
} }
@@ -180,6 +188,7 @@ export function useNostrEvents({
}) })
sub.on("eose", () => { sub.on("eose", () => {
setIsLoading(false)
onDoneCallback?.() onDoneCallback?.()
}) })

View File

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