Skip to content

Commit 228cfb9

Browse files
committed
-#2 - handled get todo tasks
1 parent 422b0b2 commit 228cfb9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import React from 'react';
22
import DisplayList from './DisplayList';
33

44
var rand = require('random-key');
5+
var api = require("../utils/api");
56

67
export default class App extends React.Component {
78

89
constructor () {
910
super();
10-
this.state = { title: '', todos: [
11-
{ title: 'eggs', done: false, id: 1 },
12-
{ title: 'banana', done: false, id: 2 },
13-
{ title: 'bread', done: false, id: 3 }
14-
] };
11+
this.state = { title: '', todos: [] };
12+
var processDataCallback = function(data) {
13+
this.setState({todos: data.todos});
14+
};
15+
16+
api.getTasks(processDataCallback.bind(this));
1517
}
1618

1719
handleDone (idToBeMarkedAsDone) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ var Constants = require("./constants");
22
var $ = require('jquery');
33

44
var api = {
5+
getTasks (processDataCallback) {
6+
var url = Constants.BASE_URL + 'todos';
7+
this.makeAjaxCall(url, 'GET', {}, processDataCallback)
8+
},
9+
510
makeAjaxCall (url, type, params, processDataCallback) {
611
$.ajax({
712
type: type,

0 commit comments

Comments
 (0)