Commit 2fc915a yinm
committed
1 parent c7ff879 commit 2fc915a Copy full SHA for 2fc915a
File tree 3 files changed +26
-3
lines changed
3 files changed +26
-3
lines changed Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
2
3
3
export default class Task extends React . Component {
4
+ handleUpdate ( e ) {
5
+ e . preventDefault ( ) ;
6
+ this . props . onTaskUpdate ( { task : { id : this . props . id , status : e . target . value } } ) ;
7
+ }
8
+
4
9
render ( ) {
5
10
return (
6
11
< tr key = { this . props . id } >
7
12
< td >
8
13
{ this . props . content }
9
14
</ td >
10
15
< td >
11
- { this . props . status }
16
+ < select defaultValue = { this . props . status } onChange = { this . handleUpdate . bind ( this ) } >
17
+ < option value = "todo" key = "todo" > todo</ option >
18
+ < option value = "doing" key = "doing" > doing</ option >
19
+ < option value = "done" key = "done" > done</ option >
20
+ </ select >
12
21
</ td >
13
22
</ tr >
14
23
) ;
Original file line number Diff line number Diff line change @@ -43,6 +43,20 @@ export default class TaskApp extends React.Component {
43
43
} ) ;
44
44
}
45
45
46
+ taskUpdate ( task ) {
47
+ request
48
+ . patch ( this . props . url + '/' + task . task . id )
49
+ . accept ( 'application/json' )
50
+ . send ( task )
51
+ . end ( ( err , res ) => {
52
+ if ( err || ! res . ok ) {
53
+ console . error ( this . props . url , status , err . toString ( ) ) ;
54
+ } else {
55
+ this . setState ( { data : res . body } ) ;
56
+ }
57
+ } ) ;
58
+ }
59
+
46
60
componentDidMount ( ) {
47
61
this . loadTaskFromServer ( ) ;
48
62
setInterval ( this . loadTaskFromServer . bind ( this ) ,
@@ -62,7 +76,7 @@ export default class TaskApp extends React.Component {
62
76
< th colSpan = "3" > </ th >
63
77
</ tr >
64
78
</ thead >
65
- < TaskList data = { this . state . data } />
79
+ < TaskList data = { this . state . data } onTaskUpdate = { this . taskUpdate . bind ( this ) } />
66
80
</ table >
67
81
</ div >
68
82
) ;
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ export default class TaskList extends React.Component {
6
6
var tasks = this . props . data . map ( ( task ) => {
7
7
return (
8
8
< Task key = { task . id } id = { task . id }
9
- content = { task . content } status = { task . status } >
9
+ content = { task . content } status = { task . status } onTaskUpdate = { this . props . onTaskUpdate } >
10
10
</ Task >
11
11
) ;
12
12
} ) ;
You can’t perform that action at this time.
0 commit comments