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:
parent
9f7a162a96
commit
e637798e05
10 changed files with 384 additions and 338 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue