diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-11-16 11:16:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-16 11:16:31 -0800 |
commit | e637798e05ba3bfc1c78be1b0f70e8b0ac22554d (patch) | |
tree | 61d60e597d406744125c4dcf71a6c63cebc3a47b /src/state/queries/service.ts | |
parent | 9f7a162a96200aaca0512765eff938a88c84d6d6 (diff) | |
download | voidsky-e637798e05ba3bfc1c78be1b0f70e8b0ac22554d.tar.zst |
Refactor account-creation to use react-query and a reducer (react-query refactor) (#1931)
* Refactor account-creation to use react-query and a reducer * Add translations * Missing translate
Diffstat (limited to 'src/state/queries/service.ts')
-rw-r--r-- | src/state/queries/service.ts | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/state/queries/service.ts b/src/state/queries/service.ts index df12d6cbc..5f7e10778 100644 --- a/src/state/queries/service.ts +++ b/src/state/queries/service.ts @@ -1,16 +1,26 @@ +import {BskyAgent} from '@atproto/api' import {useQuery} from '@tanstack/react-query' -import {useSession} from '#/state/session' - export const RQKEY = (serviceUrl: string) => ['service', serviceUrl] -export function useServiceQuery() { - const {agent} = useSession() +export function useServiceQuery(serviceUrl: string) { return useQuery({ - queryKey: RQKEY(agent.service.toString()), + 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 + } +} |