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