mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
@ -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>({
|
||||
|
@ -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()))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user