mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Restructure removing remote
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
@ -7,9 +7,8 @@ export type QueryKey = ['Account', { id: Mastodon.Account['id'] }]
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
const { id } = queryKey[1]
|
||||
|
||||
return client<Mastodon.Account>({
|
||||
return apiInstance<Mastodon.Account>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${id}`
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
@ -1,35 +0,0 @@
|
||||
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}`
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
||||
const useAccountCheckQuery = <TData = Mastodon.Account>({
|
||||
options,
|
||||
...queryKeyParams
|
||||
}: QueryKey[1] & {
|
||||
options?: UseQueryOptions<Mastodon.Account, AxiosError, TData>
|
||||
}) => {
|
||||
const queryKey: QueryKey = ['AccountCheck', { ...queryKeyParams }]
|
||||
return useQuery(queryKey, queryFunction, options)
|
||||
}
|
||||
|
||||
export { useAccountCheckQuery }
|
@ -1,4 +1,4 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import {
|
||||
useMutation,
|
||||
@ -12,9 +12,8 @@ type QueryKeyAnnouncement = ['Announcements', { showAll?: boolean }]
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKeyAnnouncement }) => {
|
||||
const { showAll } = queryKey[1]
|
||||
|
||||
return client<Mastodon.Announcement[]>({
|
||||
return apiInstance<Mastodon.Announcement[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `announcements`,
|
||||
...(showAll && {
|
||||
params: {
|
||||
@ -52,15 +51,13 @@ const mutationFunction = async ({
|
||||
}: MutationVarsAnnouncement) => {
|
||||
switch (type) {
|
||||
case 'reaction':
|
||||
return client<{}>({
|
||||
return apiInstance<{}>({
|
||||
method: me ? 'delete' : 'put',
|
||||
instance: 'local',
|
||||
url: `announcements/${id}/reactions/${name}`
|
||||
})
|
||||
case 'dismiss':
|
||||
return client<{}>({
|
||||
return apiInstance<{}>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `announcements/${id}/dismiss`
|
||||
})
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
import client from '@api/client'
|
||||
import apiGeneral from '@api/general'
|
||||
import { AxiosError } from 'axios'
|
||||
import * as AuthSession from 'expo-auth-session'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
export type QueryKey = ['Apps', { instanceDomain?: string }]
|
||||
export type QueryKey = ['Apps', { domain?: string }]
|
||||
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
const redirectUri = AuthSession.makeRedirectUri({
|
||||
@ -11,7 +11,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
useProxy: false
|
||||
})
|
||||
|
||||
const { instanceDomain } = queryKey[1]
|
||||
const { domain } = queryKey[1]
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('client_name', 'tooot')
|
||||
@ -19,11 +19,10 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
formData.append('redirect_uris', redirectUri)
|
||||
formData.append('scopes', 'read write follow push')
|
||||
|
||||
return client<Mastodon.Apps>({
|
||||
return apiGeneral<Mastodon.Apps>({
|
||||
method: 'post',
|
||||
instance: 'remote',
|
||||
instanceDomain,
|
||||
url: `apps`,
|
||||
domain: domain || '',
|
||||
url: `api/v1/apps`,
|
||||
body: formData
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
type QueryKey = ['Emojis']
|
||||
|
||||
const queryFunction = () => {
|
||||
return client<Mastodon.Emoji[]>({
|
||||
return apiInstance<Mastodon.Emoji[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'custom_emojis'
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
@ -1,18 +1,21 @@
|
||||
import client from '@api/client'
|
||||
import apiGeneral from '@api/general'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
export type QueryKey = ['Instance', { instanceDomain?: string }]
|
||||
export type QueryKey = ['Instance', { domain?: string }]
|
||||
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
const { instanceDomain } = queryKey[1]
|
||||
const queryFunction = async ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
const { domain } = queryKey[1]
|
||||
if (!domain) {
|
||||
return Promise.reject()
|
||||
}
|
||||
|
||||
return client<Mastodon.Instance>({
|
||||
const res = await apiGeneral<Mastodon.Instance>({
|
||||
method: 'get',
|
||||
instance: 'remote',
|
||||
instanceDomain,
|
||||
url: `instance`
|
||||
}).then(res => res.body)
|
||||
domain: domain,
|
||||
url: `api/v1/instance`
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const useInstanceQuery = <
|
||||
|
@ -1,13 +1,12 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
export type QueryKey = ['Lists']
|
||||
|
||||
const queryFunction = () => {
|
||||
return client<Mastodon.List[]>({
|
||||
return apiInstance<Mastodon.List[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'lists'
|
||||
}).then(res => res.body)
|
||||
}
|
||||
|
24
src/utils/queryHooks/push.ts
Normal file
24
src/utils/queryHooks/push.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
export type QueryKey = ['Push']
|
||||
|
||||
const queryFunction = async () => {
|
||||
const res = await apiInstance<Mastodon.PushSubscription>({
|
||||
method: 'get',
|
||||
url: 'push/subscription'
|
||||
})
|
||||
return res.body
|
||||
}
|
||||
|
||||
const usePushQuery = <TData = Mastodon.PushSubscription>({
|
||||
options
|
||||
}: {
|
||||
options?: UseQueryOptions<Mastodon.PushSubscription, AxiosError, TData>
|
||||
}) => {
|
||||
const queryKey: QueryKey = ['Push']
|
||||
return useQuery(queryKey, queryFunction, options)
|
||||
}
|
||||
|
||||
export { usePushQuery }
|
@ -1,4 +1,4 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import {
|
||||
useMutation,
|
||||
@ -15,9 +15,8 @@ export type QueryKeyRelationship = [
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKeyRelationship }) => {
|
||||
const { id } = queryKey[1]
|
||||
|
||||
return client<Mastodon.Relationship[]>({
|
||||
return apiInstance<Mastodon.Relationship[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/relationships`,
|
||||
params: {
|
||||
'id[]': id
|
||||
@ -57,15 +56,13 @@ type MutationVarsRelationship =
|
||||
const mutationFunction = async (params: MutationVarsRelationship) => {
|
||||
switch (params.type) {
|
||||
case 'incoming':
|
||||
return client<Mastodon.Relationship>({
|
||||
return apiInstance<Mastodon.Relationship>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `follow_requests/${params.id}/${params.payload.action}`
|
||||
}).then(res => res.body)
|
||||
case 'outgoing':
|
||||
return client<Mastodon.Relationship>({
|
||||
return apiInstance<Mastodon.Relationship>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `accounts/${params.id}/${params.payload.state ? 'un' : ''}${
|
||||
params.payload.action
|
||||
}`
|
||||
|
@ -1,4 +1,4 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useInfiniteQuery, UseInfiniteQueryOptions } from 'react-query'
|
||||
|
||||
@ -17,9 +17,8 @@ const queryFunction = ({
|
||||
const { type, id } = queryKey[1]
|
||||
let params: { [key: string]: string } = { ...pageParam }
|
||||
|
||||
return client<Mastodon.Account[]>({
|
||||
return apiInstance<Mastodon.Account[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${id}/${type}`,
|
||||
params
|
||||
})
|
||||
|
@ -1,4 +1,4 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import { AxiosError } from 'axios'
|
||||
import { useQuery, UseQueryOptions } from 'react-query'
|
||||
|
||||
@ -19,10 +19,9 @@ type SearchResult = {
|
||||
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
|
||||
const { type, term, limit = 20 } = queryKey[1]
|
||||
return client<SearchResult>({
|
||||
return apiInstance<SearchResult>({
|
||||
version: 'v2',
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'search',
|
||||
params: { ...(type && { type }), ...(term && { q: term }), limit }
|
||||
}).then(res => res.body)
|
||||
|
@ -1,4 +1,4 @@
|
||||
import client from '@api/client'
|
||||
import apiInstance from '@api/instance'
|
||||
import haptics from '@components/haptics'
|
||||
import { AxiosError } from 'axios'
|
||||
import { uniqBy } from 'lodash'
|
||||
@ -35,17 +35,15 @@ const queryFunction = ({
|
||||
|
||||
switch (page) {
|
||||
case 'Following':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'timelines/home',
|
||||
params
|
||||
})
|
||||
|
||||
case 'Local':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'timelines/public',
|
||||
params: {
|
||||
...params,
|
||||
@ -54,26 +52,23 @@ const queryFunction = ({
|
||||
})
|
||||
|
||||
case 'LocalPublic':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'timelines/public',
|
||||
params
|
||||
})
|
||||
|
||||
case 'Notifications':
|
||||
return client<Mastodon.Notification[]>({
|
||||
return apiInstance<Mastodon.Notification[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: 'notifications',
|
||||
params
|
||||
})
|
||||
|
||||
case 'Account_Default':
|
||||
if (pageParam && pageParam.hasOwnProperty('max_id')) {
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${account}/statuses`,
|
||||
params: {
|
||||
exclude_replies: 'true',
|
||||
@ -81,9 +76,8 @@ const queryFunction = ({
|
||||
}
|
||||
})
|
||||
} else {
|
||||
return client<(Mastodon.Status & { isPinned: boolean })[]>({
|
||||
return apiInstance<(Mastodon.Status & { isPinned: boolean })[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${account}/statuses`,
|
||||
params: {
|
||||
pinned: 'true'
|
||||
@ -91,9 +85,8 @@ const queryFunction = ({
|
||||
}).then(async res1 => {
|
||||
let pinned: Mastodon.Status['id'][] = []
|
||||
res1.body.forEach(status => pinned.push(status.id))
|
||||
const res2 = await client<Mastodon.Status[]>({
|
||||
const res2 = await apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${account}/statuses`,
|
||||
params: {
|
||||
exclude_replies: 'true'
|
||||
@ -108,17 +101,15 @@ const queryFunction = ({
|
||||
}
|
||||
|
||||
case 'Account_All':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${account}/statuses`,
|
||||
params
|
||||
})
|
||||
|
||||
case 'Account_Attachments':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `accounts/${account}/statuses`,
|
||||
params: {
|
||||
only_media: 'true',
|
||||
@ -127,57 +118,50 @@ const queryFunction = ({
|
||||
})
|
||||
|
||||
case 'Hashtag':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `timelines/tag/${hashtag}`,
|
||||
params
|
||||
})
|
||||
|
||||
case 'Conversations':
|
||||
return client<Mastodon.Conversation[]>({
|
||||
return apiInstance<Mastodon.Conversation[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `conversations`,
|
||||
params
|
||||
})
|
||||
|
||||
case 'Bookmarks':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `bookmarks`,
|
||||
params
|
||||
})
|
||||
|
||||
case 'Favourites':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `favourites`,
|
||||
params
|
||||
})
|
||||
|
||||
case 'List':
|
||||
return client<Mastodon.Status[]>({
|
||||
return apiInstance<Mastodon.Status[]>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `timelines/list/${list}`,
|
||||
params
|
||||
})
|
||||
|
||||
case 'Toot':
|
||||
return client<Mastodon.Status>({
|
||||
return apiInstance<Mastodon.Status>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `statuses/${toot}`
|
||||
}).then(async res1 => {
|
||||
const res2 = await client<{
|
||||
const res2 = await apiInstance<{
|
||||
ancestors: Mastodon.Status[]
|
||||
descendants: Mastodon.Status[]
|
||||
}>({
|
||||
method: 'get',
|
||||
instance: 'local',
|
||||
url: `statuses/${toot}/context`
|
||||
})
|
||||
return {
|
||||
@ -296,9 +280,8 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
|
||||
}
|
||||
})
|
||||
|
||||
return client<Mastodon.Poll>({
|
||||
return apiInstance<Mastodon.Poll>({
|
||||
method: params.payload.type === 'vote' ? 'post' : 'get',
|
||||
instance: 'local',
|
||||
url:
|
||||
params.payload.type === 'vote'
|
||||
? `polls/${params.payload.id}/votes`
|
||||
@ -306,9 +289,8 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
|
||||
...(params.payload.type === 'vote' && { body: formData })
|
||||
})
|
||||
default:
|
||||
return client<Mastodon.Status>({
|
||||
return apiInstance<Mastodon.Status>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `statuses/${params.id}/${
|
||||
params.payload.currentValue ? 'un' : ''
|
||||
}${MapPropertyToUrl[params.payload.property]}`
|
||||
@ -318,15 +300,13 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
|
||||
switch (params.payload.property) {
|
||||
case 'block':
|
||||
case 'mute':
|
||||
return client<Mastodon.Account>({
|
||||
return apiInstance<Mastodon.Account>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `accounts/${params.id}/${params.payload.property}`
|
||||
})
|
||||
case 'reports':
|
||||
return client<Mastodon.Account>({
|
||||
return apiInstance<Mastodon.Account>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `reports`,
|
||||
params: {
|
||||
account_id: params.id
|
||||
@ -334,15 +314,13 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
|
||||
})
|
||||
}
|
||||
case 'deleteItem':
|
||||
return client<Mastodon.Conversation>({
|
||||
return apiInstance<Mastodon.Conversation>({
|
||||
method: 'delete',
|
||||
instance: 'local',
|
||||
url: `${params.source}/${params.id}`
|
||||
})
|
||||
case 'domainBlock':
|
||||
return client<any>({
|
||||
return apiInstance<any>({
|
||||
method: 'post',
|
||||
instance: 'local',
|
||||
url: `domain_blocks`,
|
||||
params: {
|
||||
domain: params.domain
|
||||
|
Reference in New Issue
Block a user