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 => response.status===200? response.json() : response.text()) .then(response => response?.text ?? response) .catch(() => null) return { originalText: text, translatedText: response } } return (
{/* amber-500 */}