import { createSignal, useTransition } from 'solid-js' import './style.css' interface ITranslation { originalText: string translatedText?: string } export default function App() { const [ isPending, start ] = useTransition() const [ translation, setTranslation ] = createSignal(null) const placeholder_text = () => isPending()? 'Translating...' : 'Translation' let textarea: HTMLTextAreaElement | undefined async function fetchData(text: string) { if (text === translation()?.translatedText || !text) { return } if (translation()) { setTranslation(null) } const response = await fetch(`/api/translate?text=${text}`, { method: "POST" }).then(response => { if (response.status === 200) { return response.json() } }).then(response => response?.[0]) .catch(() => null) setTranslation({ originalText: text, translatedText: response }) } return (
{/* amber-500 */}