tooot/src/utils/queryHooks/accountCheck.ts

36 lines
938 B
TypeScript
Raw Normal View History

2021-01-07 19:13:09 +01:00
import client from '@api/client'
import { InstancesState } from '@utils/slices/instancesSlice'
import { AxiosError } from 'axios'
import { useQuery, UseQueryOptions } from 'react-query'
export type QueryKey = [
'AccountCheck',
{
id: Mastodon.Account['id']
index: NonNullable<InstancesState['local']['activeIndex']>
}
]
const queryFunction = async ({ queryKey }: { queryKey: QueryKey }) => {
const { id, index } = queryKey[1]
return client<Mastodon.Account>({
method: 'get',
instance: 'local',
localIndex: index,
url: `accounts/${id}`
2021-02-11 01:33:31 +01:00
}).then(res => res.body)
2021-01-07 19:13:09 +01:00
}
2021-01-11 21:36:57 +01:00
const useAccountCheckQuery = <TData = Mastodon.Account>({
2021-01-07 19:13:09 +01:00
options,
...queryKeyParams
}: QueryKey[1] & {
options?: UseQueryOptions<Mastodon.Account, AxiosError, TData>
}) => {
const queryKey: QueryKey = ['AccountCheck', { ...queryKeyParams }]
return useQuery(queryKey, queryFunction, options)
}
2021-01-11 21:36:57 +01:00
export { useAccountCheckQuery }