Skip to content

Commit 4c015d6

Browse files
committed
#3 - used fetch for deleting tasks
1 parent d38027d commit 4c015d6

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

ep20-using-fetch/app/components/App.jsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,10 @@ export default class App extends React.Component {
3030
}
3131

3232
handleDelete (idToBeDeleted) {
33-
var deleteTaskCallback = function(data){
34-
if (data.success) {
35-
api.getTasks()
36-
.then( (responseData) => this.setState({todos: responseData.todos} ))
37-
.catch( (error) => console.log('Failed to delete task: ', error) );
38-
}
39-
};
40-
41-
api.deleteTask(idToBeDeleted, deleteTaskCallback.bind(this));
33+
api.deleteTask(idToBeDeleted)
34+
.then( () => { return api.getTasks() })
35+
.then( (responseData) => this.setState({todos: responseData.todos} ))
36+
.catch( (error) => console.log('Failed to delete task: ', error) );
4237
}
4338

4439
handleSubmit (event) {

ep20-using-fetch/app/utils/api.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ var api = {
3737
},
3838

3939
deleteTask (idToBeDeleted, processDataCallback) {
40-
var url = Constants.BASE_URL + 'todos/' + idToBeDeleted;
41-
this.makeAjaxCall(url, 'DELETE', {}, processDataCallback)
40+
var url = this.generateUrlWithApiKey('todos/' + idToBeDeleted);
41+
return fetch(url, { method: 'DELETE' })
42+
.then((res) => res.json());
4243
},
4344

4445
makeAjaxCall (url, type, params, processDataCallback) {

0 commit comments

Comments
 (0)