1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Files
tooot/src/utils/queryHooks/users.ts
Zhiyuan Zheng e6adbf6986 Fixed #49
2021-03-15 00:18:44 +01:00

48 lines
1.1 KiB
TypeScript

import apiInstance from '@api/instance'
import { AxiosError } from 'axios'
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query'
export type QueryKeyUsers = [
'Users',
Nav.TabSharedStackParamList['Tab-Shared-Users']
]
const queryFunction = ({
queryKey,
pageParam
}: {
queryKey: QueryKeyUsers
pageParam?: { [key: string]: string }
}) => {
const { reference, id, type } = queryKey[1]
let params: { [key: string]: string } = { ...pageParam }
return apiInstance<Mastodon.Account[]>({
method: 'get',
url: `${reference}/${id}/${type}`,
params
})
}
const useUsersQuery = ({
options,
...queryKeyParams
}: QueryKeyUsers[1] & {
options?: UseInfiniteQueryOptions<
{
body: Mastodon.Account[]
links?: { prev?: string; next?: string }
},
AxiosError,
{
body: Mastodon.Account[]
links?: { prev?: string; next?: string }
}
>
}) => {
const queryKey: QueryKeyUsers = ['Users', { ...queryKeyParams }]
return useInfiniteQuery(queryKey, queryFunction, options)
}
export { useUsersQuery }