1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
This commit is contained in:
Zhiyuan Zheng
2021-01-22 01:34:20 +01:00
parent 31b2f67feb
commit 7c6aba77ba
39 changed files with 449 additions and 295 deletions

View File

@ -21,7 +21,7 @@ const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
const { instanceDomain } = queryKey[1]
const formData = new FormData()
formData.append('client_name', 'tooot📱')
formData.append('client_name', 'tooot')
formData.append('website', 'https://tooot.app')
formData.append('redirect_uris', redirectUri)
formData.append('scopes', 'read write follow push')

View File

@ -2,24 +2,56 @@ import client from '@api/client'
import { AxiosError } from 'axios'
import { useQuery, UseQueryOptions } from 'react-query'
export type QueryKey = ['Instance', { instanceDomain?: string }]
export type QueryKey = [
'Instance',
{ instanceDomain?: string; checkPublic: boolean }
]
const queryFunction = ({ queryKey }: { queryKey: QueryKey }) => {
const { instanceDomain } = queryKey[1]
const queryFunction = async ({ queryKey }: { queryKey: QueryKey }) => {
const { instanceDomain, checkPublic } = queryKey[1]
return client<Mastodon.Instance>({
let res: Mastodon.Instance & { publicAllow?: boolean } = await client<
Mastodon.Instance
>({
method: 'get',
instance: 'remote',
instanceDomain,
url: `instance`
})
if (checkPublic) {
let check
try {
check = await client<Mastodon.Status[]>({
method: 'get',
instance: 'remote',
instanceDomain,
url: `timelines/public`
})
} catch {}
if (check) {
res.publicAllow = true
return res
} else {
res.publicAllow = false
return res
}
}
return res
}
const useInstanceQuery = <TData = Mastodon.Instance>({
const useInstanceQuery = <
TData = Mastodon.Instance & { publicAllow?: boolean }
>({
options,
...queryKeyParams
}: QueryKey[1] & {
options?: UseQueryOptions<Mastodon.Instance, AxiosError, TData>
options?: UseQueryOptions<
Mastodon.Instance & { publicAllow?: boolean },
AxiosError,
TData
>
}) => {
const queryKey: QueryKey = ['Instance', { ...queryKeyParams }]
return useQuery(queryKey, queryFunction, options)

View File

@ -292,7 +292,7 @@ const mutationFunction = async (params: MutationVarsTimeline) => {
case 'poll':
const formData = new FormData()
params.payload.type === 'vote' &&
params.payload.options!.forEach((option, index) => {
params.payload.options?.forEach((option, index) => {
if (option) {
formData.append('choices[]', index.toString())
}