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
This commit is contained in:
Paul Frazee 2023-11-16 11:16:31 -08:00 committed by GitHub
parent 9f7a162a96
commit e637798e05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 384 additions and 338 deletions

View file

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