Skip to content

Commit fee1a8d

Browse files
committed
handled mark task done api call
1 parent c5963d2 commit fee1a8d

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

ep19-call-api-jquery/app/components/App.jsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,19 @@ export default class App extends React.Component {
2323

2424
todo.done = !todo.done;
2525

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);
2739
}
2840

2941
handleDelete (idToBeDeleted) {

ep19-call-api-jquery/app/utils/api.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ var api = {
77
this.makeAjaxCall(url, 'GET', processData)
88
},
99

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) {
1120
$.ajax({
1221
type: type,
1322
url: url,
1423
data: {
15-
api_key: Constants.API_KEY
24+
api_key: Constants.API_KEY,
25+
todo: params
1626
},
1727
dataType: 'json',
1828
success: function(data) {

0 commit comments

Comments
 (0)