blob: 5f7e10778be5e2603f5a68360f8c196e6e8f6c3a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
import {BskyAgent} from '@atproto/api'
import {useQuery} from '@tanstack/react-query'
export const RQKEY = (serviceUrl: string) => ['service', serviceUrl]
export function useServiceQuery(serviceUrl: string) {
return useQuery({
queryKey: RQKEY(serviceUrl),
queryFn: async () => {
const agent = new BskyAgent({service: serviceUrl})
const res = await agent.com.atproto.server.describeServer()
return res.data
},
enabled: isValidUrl(serviceUrl),
})
}
function isValidUrl(url: string) {
try {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const urlp = new URL(url)
return true
} catch {
return false
}
}
|