forked from ivacf/ivanc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArticleList.js
More file actions
executable file
·54 lines (44 loc) · 1.22 KB
/
Copy pathArticleList.js
File metadata and controls
executable file
·54 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var React = require('react');
var ArticleCard = require('./ArticleCard.js');
var FetchUtils = require('./FetchUtils');
var ArticleList = React.createClass({
loadArticlesFromServer: function() {
function parseStringDates(articles) {
articles.forEach(function(article) {
article.publish_date = new Date(article.publish_date);
});
return articles;
}
fetch(FetchUtils.buildServerURL('articles/'))
.then(FetchUtils.checkStatus)
.then(FetchUtils.parseJSON)
.then(parseStringDates)
.then(function(articlesJson) {
this.setState({articles: articlesJson});
}.bind(this))
.catch(function(error) {
console.log('Error retrieving articles', error);
});
},
getInitialState: function() {
return {articles: []};
},
componentDidMount: function() {
this.loadArticlesFromServer();
},
render: function() {
var articleNodes = this.state.articles.map(function(article) {
return (
<div className="cardContainer" key={article.id} >
<ArticleCard data={article} />
</div>
);
});
return (
<div className="articleList">
{articleNodes}
</div>
);
}
});
module.exports=ArticleList