Fetch news from api if the user is logged in

This commit is contained in:
Ray Schamp 2015-10-07 16:23:08 -04:00
parent 60d3c467fe
commit 37f0eb3348

View file

@ -24,8 +24,22 @@ var View = React.createClass({
featured: require('./featured.json')
};
},
getNews: function () {
this.api({
uri: '/news?limit=3'
}, function (err, body) {
if (!err) this.setState({'news': body});
}.bind(this));
},
componentDidUpdate: function (prevProps, prevState) {
if (this.state.session.user != prevState.session.user && this.state.session.user) {
this.getNews();
}
},
componentDidMount: function () {
// @todo API request for News
if (this.state.session.user) {
this.getNews();
}
// @todo API request for Activity
// @todo API request for Featured
},
@ -35,7 +49,7 @@ var View = React.createClass({
{this.state.session.user ? [
<div key="header" className="splash-header">
<Activity />
<News />
<News items={this.state.news} />
</div>
] : [
<Intro projectCount={this.state.projectCount} key="intro"/>