refactor: no reactivity transform (#2600)
This commit is contained in:
parent
b9394c2fa5
commit
ccfa7a8d10
102 changed files with 649 additions and 652 deletions
|
@ -60,7 +60,7 @@ interface TranslationErr {
|
|||
|
||||
export async function translateText(text: string, from: string | null | undefined, to: string) {
|
||||
const config = useRuntimeConfig()
|
||||
const status = $ref({
|
||||
const status = ref({
|
||||
success: false,
|
||||
error: '',
|
||||
text: '',
|
||||
|
@ -77,9 +77,9 @@ export async function translateText(text: string, from: string | null | undefine
|
|||
api_key: '',
|
||||
},
|
||||
}) as TranslationResponse
|
||||
status.success = true
|
||||
status.value.success = true
|
||||
// replace the translated links with the original
|
||||
status.text = response.translatedText.replace(regex, (match) => {
|
||||
status.value.text = response.translatedText.replace(regex, (match) => {
|
||||
const tagLink = regex.exec(text)
|
||||
return tagLink ? tagLink[0] : match
|
||||
})
|
||||
|
@ -87,9 +87,9 @@ export async function translateText(text: string, from: string | null | undefine
|
|||
catch (err) {
|
||||
// TODO: improve type
|
||||
if ((err as TranslationErr).data?.error)
|
||||
status.error = (err as TranslationErr).data!.error!
|
||||
status.value.error = (err as TranslationErr).data!.error!
|
||||
else
|
||||
status.error = 'Unknown Error, Please check your console in browser devtool.'
|
||||
status.value.error = 'Unknown Error, Please check your console in browser devtool.'
|
||||
console.error('Translate Post Error: ', err)
|
||||
}
|
||||
return status
|
||||
|
@ -115,10 +115,10 @@ export function useTranslation(status: mastodon.v1.Status | mastodon.v1.StatusEd
|
|||
return
|
||||
|
||||
if (!translation.text) {
|
||||
const { success, text, error } = await translateText(status.content, status.language, to)
|
||||
translation.error = error
|
||||
translation.text = text
|
||||
translation.success = success
|
||||
const translated = await translateText(status.content, status.language, to)
|
||||
translation.error = translated.value.error
|
||||
translation.text = translated.value.text
|
||||
translation.success = translated.value.success
|
||||
}
|
||||
|
||||
translation.visible = !translation.visible
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue