mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
544 migrate to react query v4 (#547)
* Update all imports * Update isLoading * Update onlineManager
This commit is contained in:
@ -1,16 +1,17 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyAccount = ['Account', { id: Mastodon.Account['id'] }]
|
||||
|
||||
const accountQueryFunction = ({ queryKey }: QueryFunctionContext<QueryKeyAccount>) => {
|
||||
const accountQueryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyAccount>) => {
|
||||
const { id } = queryKey[1]
|
||||
|
||||
return apiInstance<Mastodon.Account>({
|
||||
const res = await apiInstance<Mastodon.Account>({
|
||||
method: 'get',
|
||||
url: `accounts/${id}`
|
||||
}).then(res => res.body)
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useAccountQuery = ({
|
||||
@ -27,15 +28,16 @@ const useAccountQuery = ({
|
||||
|
||||
export type QueryKeyAccountInLists = ['AccountInLists', { id: Mastodon.Account['id'] }]
|
||||
|
||||
const accountInListsQueryFunction = ({
|
||||
const accountInListsQueryFunction = async ({
|
||||
queryKey
|
||||
}: QueryFunctionContext<QueryKeyAccountInLists>) => {
|
||||
const { id } = queryKey[1]
|
||||
|
||||
return apiInstance<Mastodon.List[]>({
|
||||
const res = await apiInstance<Mastodon.List[]>({
|
||||
method: 'get',
|
||||
url: `accounts/${id}/lists`
|
||||
}).then(res => res.body)
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useAccountInListsQuery = ({
|
||||
|
@ -6,16 +6,16 @@ import {
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
type QueryKeyAnnouncement = ['Announcements', { showAll?: boolean }]
|
||||
|
||||
const queryFunction = ({
|
||||
const queryFunction = async ({
|
||||
queryKey
|
||||
}: QueryFunctionContext<QueryKeyAnnouncement>) => {
|
||||
const { showAll } = queryKey[1]
|
||||
|
||||
return apiInstance<Mastodon.Announcement[]>({
|
||||
const res = await apiInstance<Mastodon.Announcement[]>({
|
||||
method: 'get',
|
||||
url: `announcements`,
|
||||
...(showAll && {
|
||||
@ -23,7 +23,8 @@ const queryFunction = ({
|
||||
with_dismissed: 'true'
|
||||
}
|
||||
})
|
||||
}).then(res => res.body)
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useAnnouncementQuery = ({
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyApps = ['Apps']
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
type QueryKeyEmojis = ['Emojis']
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import apiGeneral from '@api/general'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyInstance = ['Instance', { domain?: string }]
|
||||
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyLists = ['Lists']
|
||||
|
||||
|
@ -6,7 +6,7 @@ import { AxiosError } from 'axios'
|
||||
import i18next from 'i18next'
|
||||
import { RefObject } from 'react'
|
||||
import FlashMessage from 'react-native-flash-message'
|
||||
import { useMutation, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { useMutation, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
type AccountWithSource = Mastodon.Account & Required<Pick<Mastodon.Account, 'source'>>
|
||||
|
||||
|
@ -6,25 +6,26 @@ import {
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyRelationship = [
|
||||
'Relationship',
|
||||
{ id: Mastodon.Account['id'] }
|
||||
]
|
||||
|
||||
const queryFunction = ({
|
||||
const queryFunction = async ({
|
||||
queryKey
|
||||
}: QueryFunctionContext<QueryKeyRelationship>) => {
|
||||
const { id } = queryKey[1]
|
||||
|
||||
return apiInstance<Mastodon.Relationship[]>({
|
||||
const res = await apiInstance<Mastodon.Relationship[]>({
|
||||
method: 'get',
|
||||
url: `accounts/relationships`,
|
||||
params: {
|
||||
'id[]': id
|
||||
}
|
||||
}).then(res => res.body)
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useRelationshipQuery = ({
|
||||
|
@ -1,6 +1,6 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeySearch = [
|
||||
'Search',
|
||||
|
@ -1,16 +1,17 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyStatus = ['Status', { id: Mastodon.Status['id'] }]
|
||||
|
||||
const queryFunction = ({ queryKey }: QueryFunctionContext<QueryKeyStatus>) => {
|
||||
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyStatus>) => {
|
||||
const { id } = queryKey[1]
|
||||
|
||||
return apiInstance<Mastodon.Status>({
|
||||
const res = await apiInstance<Mastodon.Status>({
|
||||
method: 'get',
|
||||
url: `statuses/${id}`
|
||||
}).then(res => res.body)
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useStatusQuery = ({
|
||||
|
@ -1,6 +1,6 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyStatusesHistory = [
|
||||
'StatusesHistory',
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
UseMutationOptions,
|
||||
useQuery,
|
||||
UseQueryOptions
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
type QueryKeyFollowedTags = ['FollowedTags']
|
||||
const useFollowedTagsQuery = ({
|
||||
@ -27,10 +27,11 @@ const useFollowedTagsQuery = ({
|
||||
}
|
||||
|
||||
type QueryKeyTags = ['Tags', { tag: string }]
|
||||
const queryFunction = ({ queryKey }: QueryFunctionContext<QueryKeyTags>) => {
|
||||
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeyTags>) => {
|
||||
const { tag } = queryKey[1]
|
||||
|
||||
return apiInstance<Mastodon.Tag>({ method: 'get', url: `tags/${tag}` }).then(res => res.body)
|
||||
const res = await apiInstance<Mastodon.Tag>({ method: 'get', url: `tags/${tag}` })
|
||||
return res.body
|
||||
}
|
||||
const useTagsQuery = ({
|
||||
options,
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
useInfiniteQuery,
|
||||
UseInfiniteQueryOptions,
|
||||
useMutation
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
import deleteItem from './timeline/deleteItem'
|
||||
import editItem from './timeline/editItem'
|
||||
import updateStatusProperty from './timeline/updateStatusProperty'
|
||||
|
@ -1,5 +1,5 @@
|
||||
import queryClient from '@helpers/queryClient'
|
||||
import { InfiniteData } from 'react-query'
|
||||
import { InfiniteData } from '@tanstack/react-query'
|
||||
import { MutationVarsTimelineDeleteItem } from '../timeline'
|
||||
|
||||
const deleteItem = ({
|
||||
|
@ -1,5 +1,5 @@
|
||||
import queryClient from '@helpers/queryClient'
|
||||
import { InfiniteData } from 'react-query'
|
||||
import { InfiniteData } from '@tanstack/react-query'
|
||||
import { MutationVarsTimelineEditItem } from '../timeline'
|
||||
|
||||
const editItem = ({
|
||||
|
@ -1,5 +1,5 @@
|
||||
import queryClient from '@helpers/queryClient'
|
||||
import { InfiniteData } from 'react-query'
|
||||
import { InfiniteData } from '@tanstack/react-query'
|
||||
import { MutationVarsTimelineUpdateStatusProperty, TimelineData } from '../timeline'
|
||||
import updateConversation from './update/conversation'
|
||||
import updateNotification from './update/notification'
|
||||
|
@ -1,7 +1,7 @@
|
||||
import apiTooot from '@api/tooot'
|
||||
import haptics from '@components/haptics'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
type Translations =
|
||||
| {
|
||||
|
@ -2,7 +2,7 @@ import apiInstance from '@api/instance'
|
||||
import { store } from '@root/store'
|
||||
import { checkInstanceFeature } from '@utils/slices/instancesSlice'
|
||||
import { AxiosError } from 'axios'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from 'react-query'
|
||||
import { QueryFunctionContext, useQuery, UseQueryOptions } from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyTrends = ['Trends', { type: 'tags' | 'statuses' | 'links' }]
|
||||
|
||||
|
@ -5,7 +5,7 @@ import {
|
||||
QueryFunctionContext,
|
||||
useInfiniteQuery,
|
||||
UseInfiniteQueryOptions
|
||||
} from 'react-query'
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
export type QueryKeyUsers = [
|
||||
'Users',
|
||||
|
Reference in New Issue
Block a user