forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useQuery} from '@tanstack/react-query'
2
3import {Agent} from '../session/agent'
4
5const RQKEY_ROOT = 'service'
6export const RQKEY = (serviceUrl: string) => [RQKEY_ROOT, serviceUrl]
7
8export function useServiceQuery(serviceUrl: string) {
9 return useQuery({
10 queryKey: RQKEY(serviceUrl),
11 queryFn: async () => {
12 const agent = new Agent(null, {service: serviceUrl})
13 const res = await agent.com.atproto.server.describeServer()
14 return res.data
15 },
16 enabled: isValidUrl(serviceUrl),
17 })
18}
19
20function isValidUrl(url: string) {
21 try {
22 // eslint-disable-next-line @typescript-eslint/no-unused-vars
23 const urlp = new URL(url)
24 return true
25 } catch {
26 return false
27 }
28}