-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathApp.tsx
58 lines (53 loc) · 1.53 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { useState } from 'react'
import { invoke } from '@tauri-apps/api/tauri'
import './App.css'
import { DndExample } from './Dnd'
function App() {
const [msgFromRust, setMsgFromRust] = useState('')
const [inputValue, setInputValue] = useState('')
const [isDndView, setIsDndView] = useState(false)
const handleHelloWorld = async () => {
try {
const response = await invoke('hello_world_test', {
event: inputValue || 'nope',
})
setMsgFromRust(`${response}`)
console.log('response ', response)
} catch (error) {
console.log('error ', error)
}
}
return (
<div className='app'>
<div className='btn-toggle-container'>
<button
className='btn-toggle'
aria-label='toggle view'
onClick={() => setIsDndView(!isDndView)}
>{isDndView ? '💧' : '🔥'}</button>
</div>
{isDndView ? (
<DndExample />
) : (
<header className='App-header'>
<div className='component-wrapper'>
<input
value={inputValue}
placeholder='input for rust'
onChange={(e) => setInputValue(e.target.value)}
/>
<button className='btn' onClick={handleHelloWorld}>
call rust
</button>
{!!msgFromRust && (
<p style={{ position: 'absolute' }}>
response message: {msgFromRust}
</p>
)}
</div>
</header>
)}
</div>
)
}
export default App