mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-26 17:16:11 -05:00
Fetch news from api if the user is logged in
This commit is contained in:
parent
60d3c467fe
commit
37f0eb3348
1 changed files with 16 additions and 2 deletions
|
@ -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"/>
|
||||
|
|
Loading…
Reference in a new issue