bsky-app/src/state/queries/service.ts
Paul Frazee fcd22d4ccb
Adjust stale-caches and dont group read&unread notifs together (#2041)
* Dont group read & unread notifications together

* Remove and reduce some stale cache times

* Keep the staleTime on the post-feed

* Bring back the load-bearing staletime on profile
2023-11-29 20:27:39 -08:00

26 lines
678 B
TypeScript

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