1cdbfc7092
* add config (with temp config) * only allow whitelisted domains in form * move config to generic config * use array-based config * update deps * rm expect-error
40 lines
985 B
TypeScript
40 lines
985 B
TypeScript
import {useQuery} from '@tanstack/react-query'
|
|
|
|
import {STALE} from '#/state/queries'
|
|
import {useAgent} from '#/state/session'
|
|
|
|
type ServiceConfig = {
|
|
checkEmailConfirmed: boolean
|
|
topicsEnabled: boolean
|
|
liveNow: {
|
|
did: string
|
|
domains: string[]
|
|
}[]
|
|
}
|
|
|
|
export function useServiceConfigQuery() {
|
|
const agent = useAgent()
|
|
return useQuery<ServiceConfig>({
|
|
refetchOnWindowFocus: true,
|
|
staleTime: STALE.MINUTES.FIVE,
|
|
queryKey: ['service-config'],
|
|
queryFn: async () => {
|
|
try {
|
|
const {data} = await agent.api.app.bsky.unspecced.getConfig()
|
|
return {
|
|
checkEmailConfirmed: Boolean(data.checkEmailConfirmed),
|
|
// @ts-expect-error not included in types atm
|
|
topicsEnabled: Boolean(data.topicsEnabled),
|
|
liveNow: data.liveNow ?? [],
|
|
}
|
|
} catch (e) {
|
|
return {
|
|
checkEmailConfirmed: false,
|
|
topicsEnabled: false,
|
|
liveNow: [],
|
|
}
|
|
}
|
|
},
|
|
})
|
|
}
|