Skip to content

Commit 9b44f38

Browse files
committed
handled mark task delete api call
1 parent fee1a8d commit 9b44f38

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,19 @@ export default class App extends React.Component {
3939
}
4040

4141
handleDelete (idToBeDeleted) {
42-
var newTodos = this.state.todos.filter( (todo) => {
43-
return todo.id != idToBeDeleted
44-
} )
42+
var processData = function(data) {
43+
this.setState({todos: data.todos});
44+
};
45+
46+
var markTaskDeleteCallback = function(data){
47+
if(data.success){
48+
api.getTasks(processData.bind(this));
49+
} else {
50+
console.log("Failed to delete task")
51+
}
52+
};
4553

46-
this.setState({ todos: newTodos});
54+
api.deleteTask(markTaskDeleteCallback.bind(this), idToBeDeleted);
4755
}
4856

4957
handleSubmit (event) {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ var api = {
1010
markTaskDone (processData, todo) {
1111
var url = Constants.BASE_URL + 'todos/' + todo.id;
1212
var params = {
13-
id: todo.id,
1413
done: todo.done
1514
};
1615
this.makeAjaxCall(url, 'PUT', processData, params)
1716
},
1817

18+
deleteTask (processData, idToBeDeleted) {
19+
var url = Constants.BASE_URL + 'todos/' + idToBeDeleted;
20+
this.makeAjaxCall(url, 'DELETE', processData)
21+
},
22+
1923
makeAjaxCall (url, type, processDataCallback, params) {
2024
$.ajax({
2125
type: type,

0 commit comments

Comments
 (0)