mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Fixed #49
This commit is contained in:
47
src/utils/queryHooks/users.ts
Normal file
47
src/utils/queryHooks/users.ts
Normal file
@ -0,0 +1,47 @@
|
||||
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 }
|
Reference in New Issue
Block a user