1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00
Also reported by other users
This commit is contained in:
xmflsct
2023-01-14 16:58:01 +01:00
parent e7ca5ba63d
commit e5744aba06
4 changed files with 17 additions and 20 deletions

View File

@ -13,7 +13,7 @@ export type Params = {
}
headers?: { [key: string]: string }
body?: FormData
extras?: Omit<AxiosRequestConfig, 'method' | 'url' | 'params' | 'headers' | 'data'>
extras?: Omit<AxiosRequestConfig, 'method' | 'baseURL' | 'url' | 'params' | 'headers' | 'data'>
}
const apiInstance = async <T = unknown>({

View File

@ -18,8 +18,8 @@ export type SearchResult = {
statuses: Mastodon.Status[]
}
const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeySearch>) => {
const { type, term, limit = 20 } = queryKey[1]
const queryFunction = async ({ queryKey, meta }: QueryFunctionContext<QueryKeySearch>) => {
const { type, term, limit = 10 } = queryKey[1]
if (!term?.length) {
return Promise.reject('Empty search term')
}
@ -32,7 +32,8 @@ const queryFunction = async ({ queryKey }: QueryFunctionContext<QueryKeySearch>)
...(type && { type }),
limit,
resolve: true
}
},
...(meta && { extras: meta })
})
return res.body
}
@ -50,7 +51,12 @@ const useSearchQuery = <T = SearchResult>({
export const searchLocalStatus = async (uri: Mastodon.Status['uri']): Promise<Mastodon.Status> => {
const queryKey: QueryKeySearch = ['Search', { type: 'statuses', term: uri, limit: 1 }]
return await queryClient
.fetchQuery(queryKey, queryFunction, { staleTime: 3600, cacheTime: 3600 })
.fetchQuery(queryKey, queryFunction, {
staleTime: 3600,
cacheTime: 3600,
retry: false,
meta: { timeout: 1000 }
})
.then(res =>
res.statuses[0]?.uri === uri || res.statuses[0]?.url === uri
? res.statuses[0]
@ -63,7 +69,12 @@ export const searchLocalAccount = async (
): Promise<Mastodon.Account> => {
const queryKey: QueryKeySearch = ['Search', { type: 'accounts', term: url, limit: 1 }]
return await queryClient
.fetchQuery(queryKey, queryFunction, { staleTime: 3600, cacheTime: 3600 })
.fetchQuery(queryKey, queryFunction, {
staleTime: 3600,
cacheTime: 3600,
retry: false,
meta: { timeout: 1000 }
})
.then(res => (res.accounts[0].url === url ? res.accounts[0] : Promise.reject()))
}