mirror of
https://github.com/tooot-app/app
synced 2025-06-05 22:19:13 +02:00
Basic translation working
This commit is contained in:
30
src/utils/queryHooks/translate.ts
Normal file
30
src/utils/queryHooks/translate.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import apiGeneral from '@api/general'
|
||||
import { useQuery } from 'react-query'
|
||||
|
||||
export type QueryKeyTranslate = [
|
||||
'Translate',
|
||||
{ toot: string; source: string; target: string }
|
||||
]
|
||||
|
||||
const queryFunction = ({ queryKey }: { queryKey: QueryKeyTranslate }) => {
|
||||
const { toot, source, target } = queryKey[1]
|
||||
|
||||
return apiGeneral<Translate.Translate>({
|
||||
domain: 'translate.tooot.app',
|
||||
method: 'post',
|
||||
url: 'translate',
|
||||
params: {
|
||||
api_key: '65180371-1ddb-4ec0-9aa3-ac47d371c41a',
|
||||
q: toot,
|
||||
source,
|
||||
target
|
||||
}
|
||||
}).then(res => res.body.translatedText)
|
||||
}
|
||||
|
||||
const useTranslateQuery = (queryKeyParams: QueryKeyTranslate[1]) => {
|
||||
const queryKey: QueryKeyTranslate = ['Translate', { ...queryKeyParams }]
|
||||
return useQuery(queryKey, queryFunction)
|
||||
}
|
||||
|
||||
export { useTranslateQuery }
|
Reference in New Issue
Block a user