scratch-www/src/views/splash/splash.jsx

77 lines
2.4 KiB
React
Raw Normal View History

2015-09-02 15:08:58 -04:00
var React = require('react');
var Render = require('../../lib/render.jsx');
2015-09-02 15:08:58 -04:00
var Api = require('../../mixins/api.jsx');
2015-09-03 22:41:27 -04:00
var Session = require('../../mixins/session.jsx');
2015-09-08 22:54:55 -04:00
var Activity = require('../../components/activity/activity.jsx');
2015-09-08 18:15:02 -04:00
var Box = require('../../components/box/box.jsx');
var Carousel = require('../../components/carousel/carousel.jsx');
var Intro = require('../../components/intro/intro.jsx');
2015-09-02 15:08:58 -04:00
var News = require('../../components/news/news.jsx');
require('./splash.scss');
2015-10-09 16:16:37 -04:00
var Splash = React.createClass({
type: 'Splash',
2015-09-02 15:08:58 -04:00
mixins: [
2015-09-03 22:41:27 -04:00
Api,
Session
2015-09-02 15:08:58 -04:00
],
getInitialState: function () {
return {
projectCount: 10569070,
2015-09-03 22:41:27 -04:00
activity: [],
news: [],
2015-09-08 18:15:02 -04:00
featured: require('./featured.json')
2015-09-02 15:08:58 -04:00
};
},
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();
}
},
2015-09-02 15:08:58 -04:00
componentDidMount: function () {
if (this.state.session.user) {
this.getNews();
}
2015-09-02 16:33:31 -04:00
// @todo API request for Activity
// @todo API request for Featured
2015-09-02 15:08:58 -04:00
},
render: function () {
return (
2015-09-03 22:41:27 -04:00
<div className="inner">
2015-10-07 11:48:55 -04:00
{this.state.session.user ? [
2015-09-29 15:25:10 -04:00
<div key="header" className="splash-header">
2015-09-21 12:35:00 -04:00
<Activity />
<News items={this.state.news} />
2015-09-21 12:35:00 -04:00
</div>
2015-09-16 14:44:26 -04:00
] : [
<Intro projectCount={this.state.projectCount} key="intro"/>
]}
2015-09-10 15:00:07 -04:00
{this.state.featured.map(function (set) {
2015-09-08 18:15:02 -04:00
return (
<Box
key={set.title}
className="featured"
title={set.title}
moreTitle={set.moreTitle}
moreHref={set.moreHref}>
2015-09-08 18:15:02 -04:00
<Carousel items={set.items} />
</Box>
);
})}
2015-09-02 15:08:58 -04:00
</div>
);
}
});
Render(<Splash />, document.getElementById('view'));