feat: groups badge

This commit is contained in:
codytseng
2025-01-18 14:42:37 +08:00
parent 1644a92615
commit 49933ee4a2
6 changed files with 48 additions and 13 deletions

View File

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

View 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 }
}