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