update interface visuals
Browse files- .gitignore +3 -0
- src/Home/index.tsx +8 -3
.gitignore
CHANGED
@@ -12,6 +12,9 @@ dist
|
|
12 |
dist-ssr
|
13 |
*.local
|
14 |
output
|
|
|
|
|
|
|
15 |
|
16 |
# Editor directories and files
|
17 |
.vscode/*
|
|
|
12 |
dist-ssr
|
13 |
*.local
|
14 |
output
|
15 |
+
tsconfig.app.tsbuildinfo
|
16 |
+
tsconfig.node.tsbuildinfo
|
17 |
+
|
18 |
|
19 |
# Editor directories and files
|
20 |
.vscode/*
|
src/Home/index.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import { createSignal } from 'solid-js'
|
2 |
import './style.css'
|
3 |
|
4 |
|
@@ -9,11 +9,14 @@ interface ITranslation {
|
|
9 |
}
|
10 |
|
11 |
export default function App() {
|
|
|
12 |
const [ translation, setTranslation ] = createSignal<ITranslation | null>(null)
|
|
|
13 |
let textarea: HTMLTextAreaElement | undefined
|
14 |
|
15 |
async function fetchData(text: string) {
|
16 |
if (text === translation()?.translatedText || !text) { return }
|
|
|
17 |
const response = await fetch(`/api/translate?text=${text}`, { method: "POST" }).then(response => {
|
18 |
if (response.status === 200) { return response.json() }
|
19 |
|
@@ -26,12 +29,14 @@ export default function App() {
|
|
26 |
return (
|
27 |
<main class="w-screen my-24 mx-5">
|
28 |
<div class="w-1/2 p-3 flex justify-end">
|
29 |
-
<button onclick={() =>
|
|
|
|
|
30 |
</div>
|
31 |
<section class="flex">
|
32 |
{/* amber-500 */}
|
33 |
<textarea class="h-64 p-2 w-1/2 bg-zinc-700" placeholder="Insert input text..." ref={textarea} />
|
34 |
-
<textarea class="h-64 p-7 w-1/2 text-2xl" placeholder=
|
35 |
</section>
|
36 |
</main>
|
37 |
)
|
|
|
1 |
+
import { createSignal, useTransition } from 'solid-js'
|
2 |
import './style.css'
|
3 |
|
4 |
|
|
|
9 |
}
|
10 |
|
11 |
export default function App() {
|
12 |
+
const [ isPending, start ] = useTransition()
|
13 |
const [ translation, setTranslation ] = createSignal<ITranslation | null>(null)
|
14 |
+
const placeholder_text = () => isPending()? 'Translating...' : 'Translation'
|
15 |
let textarea: HTMLTextAreaElement | undefined
|
16 |
|
17 |
async function fetchData(text: string) {
|
18 |
if (text === translation()?.translatedText || !text) { return }
|
19 |
+
if (translation()) { setTranslation(null) }
|
20 |
const response = await fetch(`/api/translate?text=${text}`, { method: "POST" }).then(response => {
|
21 |
if (response.status === 200) { return response.json() }
|
22 |
|
|
|
29 |
return (
|
30 |
<main class="w-screen my-24 mx-5">
|
31 |
<div class="w-1/2 p-3 flex justify-end">
|
32 |
+
<button onclick={() => {
|
33 |
+
start(() => fetchData(textarea?.value as string))
|
34 |
+
} }>Translate</button>
|
35 |
</div>
|
36 |
<section class="flex">
|
37 |
{/* amber-500 */}
|
38 |
<textarea class="h-64 p-2 w-1/2 bg-zinc-700" placeholder="Insert input text..." ref={textarea} />
|
39 |
+
<textarea class="h-64 p-7 w-1/2 text-2xl" placeholder={placeholder_text()} readonly value={translation()?.translatedText ?? ''} />
|
40 |
</section>
|
41 |
</main>
|
42 |
)
|