playmak3r commited on
Commit
94ecbeb
1 Parent(s): ff284fc

add functionality to the interface

Browse files
Files changed (2) hide show
  1. package.json +2 -1
  2. src/Home/index.tsx +32 -12
package.json CHANGED
@@ -8,7 +8,8 @@
8
  "build": "tsc -b && vite build",
9
  "preview": "vite preview",
10
  "css:dev": "tailwindcss -i src/input.css -o output/output.css --watch",
11
- "build:css": "tailwindcss -i src/input.css -o output/output.css"
 
12
  },
13
  "dependencies": {
14
  "solid-js": "^1.9.1"
 
8
  "build": "tsc -b && vite build",
9
  "preview": "vite preview",
10
  "css:dev": "tailwindcss -i src/input.css -o output/output.css --watch",
11
+ "build:css": "tailwindcss -i src/input.css -o output/output.css",
12
+ "start": "cd server && python app.py"
13
  },
14
  "dependencies": {
15
  "solid-js": "^1.9.1"
src/Home/index.tsx CHANGED
@@ -1,20 +1,40 @@
 
1
  import './style.css'
2
 
3
 
 
 
 
 
 
 
4
  export default function App() {
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- return (
7
- <main class="w-screen my-24 mx-5">
8
- <div class="w-1/2 p-3 flex justify-end">
9
- <button>Translate</button>
10
- </div>
11
- <section class="flex">
12
- {/* amber-500 */}
13
- <textarea class="h-64 p-2 w-1/2 bg-zinc-700" placeholder="Insert input text..." />
14
- <textarea class="h-64 p-7 w-1/2 text-2xl" placeholder='Translation' readonly />
15
- </section>
16
- </main>
17
- )
18
  }
19
 
20
 
 
1
+ import { createSignal } from 'solid-js'
2
  import './style.css'
3
 
4
 
5
+
6
+ interface ITranslation {
7
+ originalText: string
8
+ translatedText?: string
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
+
20
+ }).then(response => response?.[0])
21
+ .catch(() => null)
22
+
23
+ setTranslation({ originalText: text, translatedText: response })
24
+ }
25
 
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={() => fetchData(textarea?.value as string)}>Translate</button>
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='Translation' readonly value={translation()?.translatedText} />
35
+ </section>
36
+ </main>
37
+ )
38
  }
39
 
40