File tree Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Expand file tree Collapse file tree 2 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,19 @@ export default class App extends React.Component {
23
23
24
24
todo . done = ! todo . done ;
25
25
26
- this . setState ( { todos : _todos } ) ;
26
+ var processData = function ( data ) {
27
+ this . setState ( { todos : data . todos } ) ;
28
+ } ;
29
+
30
+ var markTaskDoneCallback = function ( data ) {
31
+ if ( data . success ) {
32
+ api . getTasks ( processData . bind ( this ) ) ;
33
+ } else {
34
+ console . log ( "Failed to mark task as done/undone" )
35
+ }
36
+ } ;
37
+
38
+ api . markTaskDone ( markTaskDoneCallback . bind ( this ) , todo ) ;
27
39
}
28
40
29
41
handleDelete ( idToBeDeleted ) {
Original file line number Diff line number Diff line change @@ -7,12 +7,22 @@ var api = {
7
7
this . makeAjaxCall ( url , 'GET' , processData )
8
8
} ,
9
9
10
- makeAjaxCall ( url , type , processDataCallback ) {
10
+ markTaskDone ( processData , todo ) {
11
+ var url = Constants . BASE_URL + 'todos/' + todo . id ;
12
+ var params = {
13
+ id : todo . id ,
14
+ done : todo . done
15
+ } ;
16
+ this . makeAjaxCall ( url , 'PUT' , processData , params )
17
+ } ,
18
+
19
+ makeAjaxCall ( url , type , processDataCallback , params ) {
11
20
$ . ajax ( {
12
21
type : type ,
13
22
url : url ,
14
23
data : {
15
- api_key : Constants . API_KEY
24
+ api_key : Constants . API_KEY ,
25
+ todo : params
16
26
} ,
17
27
dataType : 'json' ,
18
28
success : function ( data ) {
You can’t perform that action at this time.
0 commit comments