1
- import { useQuery } from '@wasp/queries'
2
1
import getTasks from '@wasp/queries/getTasks'
3
2
import createTask from '@wasp/actions/createTask'
3
+ import { useQuery } from '@wasp/queries'
4
4
import updateTask from '@wasp/actions/updateTask'
5
5
import logout from '@wasp/auth/logout'
6
- import Clocks from './Clocks'
7
6
8
7
const MainPage = ( ) => {
9
- const { data : tasks , isFetching , error } = useQuery ( getTasks )
8
+ const { data : tasks , isLoading , error } = useQuery ( getTasks )
10
9
11
10
return (
12
11
< div >
13
12
< NewTaskForm />
14
13
15
14
{ tasks && < TasksList tasks = { tasks } /> }
16
15
17
- < div > < Clocks /> </ div >
18
-
19
- { isFetching && 'Fetching...' }
16
+ { isLoading && 'Loading...' }
20
17
{ error && 'Error: ' + error }
21
-
22
- < button onClick = { logout } > Logout </ button >
18
+ < button onClick = { logout } > Logout</ button >
23
19
</ div >
24
20
)
25
21
}
26
22
27
- const Task = ( props ) => {
23
+ const Task = ( { task } ) => {
28
24
const handleIsDoneChange = async ( event ) => {
29
25
try {
30
26
await updateTask ( {
31
- taskId : props . task . id ,
32
- data : { isDone : event . target . checked }
27
+ id : task . id ,
28
+ isDone : event . target . checked ,
33
29
} )
34
30
} catch ( error ) {
35
31
window . alert ( 'Error while updating task: ' + error . message )
@@ -38,26 +34,35 @@ const Task = (props) => {
38
34
return (
39
35
< div >
40
36
< input
41
- type = 'checkbox' id = { props . task . id }
42
- checked = { props . task . isDone }
37
+ type = "checkbox"
38
+ id = { String ( task . id ) }
39
+ checked = { task . isDone }
43
40
onChange = { handleIsDoneChange }
44
41
/>
45
- { props . task . description }
42
+ { task . description }
46
43
</ div >
47
44
)
48
45
}
49
46
50
- const TasksList = ( props ) => {
51
- if ( ! props . tasks ?. length ) return 'No tasks'
52
- return props . tasks . map ( ( task , idx ) => < Task task = { task } key = { idx } /> )
47
+ const TasksList = ( { tasks } ) => {
48
+ if ( ! tasks ?. length ) return < div > No tasks</ div >
49
+
50
+ return (
51
+ < div >
52
+ { tasks . map ( ( task , idx ) => (
53
+ < Task task = { task } key = { idx } />
54
+ ) ) }
55
+ </ div >
56
+ )
53
57
}
54
58
55
- const NewTaskForm = ( props ) => {
59
+ const NewTaskForm = ( ) => {
56
60
const handleSubmit = async ( event ) => {
57
61
event . preventDefault ( )
58
62
try {
59
- const description = event . target . description . value
60
- event . target . reset ( )
63
+ const target = event . target
64
+ const description = target . description . value
65
+ target . reset ( )
61
66
await createTask ( { description } )
62
67
} catch ( err ) {
63
68
window . alert ( 'Error: ' + err . message )
@@ -66,15 +71,10 @@ const NewTaskForm = (props) => {
66
71
67
72
return (
68
73
< form onSubmit = { handleSubmit } >
69
- < input
70
- name = 'description'
71
- type = 'text'
72
- defaultValue = ''
73
- />
74
- < input type = 'submit' value = 'Create task' />
74
+ < input name = "description" type = "text" defaultValue = "" />
75
+ < input type = "submit" value = "Create task" />
75
76
</ form >
76
77
)
77
78
}
78
79
79
80
export default MainPage
80
-
0 commit comments