mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {useQuery} from '@tanstack/react-query'
2
3import {STALE} from '#/state/queries'
4import {useAgent} from '#/state/session'
5
6type ServiceConfig = {
7 checkEmailConfirmed: boolean
8 topicsEnabled: boolean
9}
10
11export function useServiceConfigQuery() {
12 const agent = useAgent()
13 return useQuery<ServiceConfig>({
14 refetchOnWindowFocus: true,
15 staleTime: STALE.MINUTES.FIVE,
16 queryKey: ['service-config'],
17 queryFn: async () => {
18 try {
19 const {data} = await agent.api.app.bsky.unspecced.getConfig()
20 return {
21 checkEmailConfirmed: Boolean(data.checkEmailConfirmed),
22 topicsEnabled: Boolean(data.topicsEnabled),
23 }
24 } catch (e) {
25 return {
26 checkEmailConfirmed: false,
27 topicsEnabled: false,
28 }
29 }
30 },
31 })
32}