feat: groups badge
This commit is contained in:
@@ -3,6 +3,8 @@ export * from './useFetchEvent'
|
||||
export * from './useFetchFollowings'
|
||||
export * from './useFetchNip05'
|
||||
export * from './useFetchProfile'
|
||||
export * from './useFetchRelayInfo'
|
||||
export * from './useFetchRelayInfos'
|
||||
export * from './useFetchRelayList'
|
||||
export * from './useSearchParams'
|
||||
export * from './useSearchProfiles'
|
||||
|
||||
30
src/hooks/useFetchRelayInfo.tsx
Normal file
30
src/hooks/useFetchRelayInfo.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import client from '@/services/client.service'
|
||||
import { TRelayInfo } from '@/types'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export function useFetchRelayInfo(url: string) {
|
||||
const [isFetching, setIsFetching] = useState(true)
|
||||
const [relayInfo, setRelayInfo] = useState<TRelayInfo | undefined>(undefined)
|
||||
|
||||
useEffect(() => {
|
||||
const fetchRelayInfos = async () => {
|
||||
setIsFetching(true)
|
||||
const timer = setTimeout(() => {
|
||||
setIsFetching(false)
|
||||
}, 5000)
|
||||
try {
|
||||
const [relayInfo] = await client.fetchRelayInfos([url])
|
||||
setRelayInfo(relayInfo)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
} finally {
|
||||
clearTimeout(timer)
|
||||
setIsFetching(false)
|
||||
}
|
||||
}
|
||||
|
||||
fetchRelayInfos()
|
||||
}, [url])
|
||||
|
||||
return { relayInfo, isFetching }
|
||||
}
|
||||
Reference in New Issue
Block a user