1
0
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:
Zhiyuan Zheng
2021-05-19 20:40:16 +02:00
parent 2b838601d5
commit 67d3589f30
5 changed files with 107 additions and 0 deletions

View 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 }