fix: type errors (#802)

This commit is contained in:
三咲智子 Kevin Deng 2023-01-06 00:48:20 +08:00 committed by GitHub
parent 272fb4a13d
commit acdb94de62
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 113 additions and 74 deletions

View file

@ -1,4 +1,4 @@
import type { Status } from 'masto'
import type { Status, StatusEdit } from 'masto'
export interface TranslationResponse {
translatedText: string
@ -24,15 +24,18 @@ export async function translateText(text: string, from?: string | null, to?: str
return translatedText
}
const translations = new WeakMap<Status, { visible: boolean; text: string }>()
const translations = new WeakMap<Status | StatusEdit, { visible: boolean; text: string }>()
export function useTranslation(status: Status) {
export function useTranslation(status: Status | StatusEdit) {
if (!translations.has(status))
translations.set(status, reactive({ visible: false, text: '' }))
const translation = translations.get(status)!
async function toggle() {
if (!('language' in status))
return
if (!translation.text)
translation.text = await translateText(status.content, status.language)