2015-09-02 15:08:58 -04:00
|
|
|
var React = require('react');
|
2015-10-16 15:10:17 -04:00
|
|
|
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-10-19 14:15:56 -04:00
|
|
|
var AdminPanel = require('../../components/adminpanel/adminpanel.jsx');
|
2015-09-08 18:15:02 -04:00
|
|
|
var Box = require('../../components/box/box.jsx');
|
2015-10-19 14:15:56 -04:00
|
|
|
var Button = require('../../components/forms/button.jsx');
|
2015-09-08 18:15:02 -04:00
|
|
|
var Carousel = require('../../components/carousel/carousel.jsx');
|
2015-09-09 22:16:03 -04:00
|
|
|
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 {
|
2015-09-09 22:16:03 -04:00
|
|
|
projectCount: 10569070,
|
2015-09-03 22:41:27 -04:00
|
|
|
activity: [],
|
|
|
|
news: [],
|
2015-10-20 13:18:57 -04:00
|
|
|
featuredCustom: {},
|
|
|
|
featuredGlobal: {}
|
2015-09-02 15:08:58 -04:00
|
|
|
};
|
|
|
|
},
|
2015-10-20 13:18:57 -04:00
|
|
|
getGlobalHomepageRows: function () {
|
|
|
|
this.api({
|
|
|
|
uri: '/proxy/featured'
|
|
|
|
}, function (err, body) {
|
|
|
|
if (!err) this.setState({featuredGlobal: body});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
getCustomHomepageRows: function () {
|
|
|
|
this.api({
|
|
|
|
uri: '/proxy/users/' + this.state.session.user.id + '/featured'
|
|
|
|
}, function (err, body) {
|
|
|
|
if (!err) this.setState({featuredCustom: body});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
2015-10-07 16:23:08 -04:00
|
|
|
componentDidUpdate: function (prevProps, prevState) {
|
2015-10-20 13:18:57 -04:00
|
|
|
if (this.state.session.user != prevState.session.user) {
|
|
|
|
if (this.state.session.user) {
|
|
|
|
this.getActivity();
|
|
|
|
this.getCustomHomepageRows();
|
|
|
|
this.getNews();
|
|
|
|
} else {
|
|
|
|
this.setState({featuredCustom: []});
|
|
|
|
}
|
2015-10-07 16:23:08 -04:00
|
|
|
}
|
|
|
|
},
|
2015-09-02 15:08:58 -04:00
|
|
|
componentDidMount: function () {
|
2015-10-20 13:18:57 -04:00
|
|
|
this.getGlobalHomepageRows();
|
2015-10-07 16:23:08 -04:00
|
|
|
if (this.state.session.user) {
|
2015-10-20 12:25:30 -04:00
|
|
|
this.getActivity();
|
2015-10-20 13:18:57 -04:00
|
|
|
this.getCustomHomepageRows();
|
|
|
|
this.getNews();
|
2015-10-07 16:23:08 -04:00
|
|
|
}
|
2015-09-02 15:08:58 -04:00
|
|
|
},
|
2015-10-20 12:25:30 -04:00
|
|
|
getNews: function () {
|
|
|
|
this.api({
|
|
|
|
uri: '/news?limit=3'
|
|
|
|
}, function (err, body) {
|
|
|
|
if (!err) this.setState({'news': body});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
getActivity: function () {
|
|
|
|
this.api({
|
|
|
|
uri: '/proxy/users/' + this.state.session.user.username + '/activity?max=5'
|
|
|
|
}, function (err, body) {
|
|
|
|
if (!err) this.setState({'activity': body});
|
|
|
|
}.bind(this));
|
|
|
|
},
|
2015-10-20 13:18:57 -04:00
|
|
|
renderHomepageRows: function () {
|
|
|
|
var rows = [
|
|
|
|
<Box title="Featured Projects" key="community_featured_projects">
|
|
|
|
<Carousel items={this.state.featuredGlobal.community_featured_projects} />
|
|
|
|
</Box>,
|
|
|
|
<Box title="Featured Studios" key="community_featured_studios">
|
|
|
|
<Carousel items={this.state.featuredGlobal.community_featured_studios} />
|
|
|
|
</Box>
|
|
|
|
];
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.state.featuredGlobal.curator_top_projects &&
|
|
|
|
this.state.featuredGlobal.curator_top_projects.length > 4) {
|
|
|
|
rows.push(
|
|
|
|
<Box
|
|
|
|
key="curator_top_projects"
|
|
|
|
title={
|
|
|
|
'Projects Curated by ' +
|
|
|
|
this.state.featuredGlobal.curator_top_projects[0].curator_name}
|
|
|
|
moreTitle="Learn More"
|
|
|
|
moreHref="/studios/386359/">
|
|
|
|
<Carousel items={this.state.featuredGlobal.curator_top_projects} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (
|
|
|
|
this.state.featuredGlobal.scratch_design_studio &&
|
|
|
|
this.state.featuredGlobal.scratch_design_studio.length > 4) {
|
|
|
|
rows.push(
|
|
|
|
<Box
|
|
|
|
key="scratch_design_studio"
|
|
|
|
title={
|
|
|
|
'Scratch Design Studio - ' +
|
|
|
|
this.state.featuredGlobal.scratch_design_studio[0].gallery_title}
|
|
|
|
moreTitle="Visit the studio"
|
|
|
|
moreHref={'/studios/' + this.state.featuredGlobal.scratch_design_studio[0].gallery_id + '/'}>
|
|
|
|
<Carousel items={this.state.featuredGlobal.scratch_design_studio} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.session.user) {
|
|
|
|
rows.push(
|
|
|
|
<Box title="Recently Shared Projects" key="community_newest_projects">
|
|
|
|
<Carousel items={this.state.featuredGlobal.community_newest_projects} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.featuredCustom.custom_projects_by_following) {
|
|
|
|
rows.push(
|
|
|
|
<Box title="Projects by Scratchers I'm Following" key="custom_projects_by_following">
|
|
|
|
<Carousel items={this.state.featuredCustom.custom_projects_by_following} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (this.state.featuredCustom.custom_projects_loved_by_following) {
|
|
|
|
rows.push(
|
|
|
|
<Box title="Projects Loved by Scratchers I'm Following" key="custom_projects_loved_by_following">
|
|
|
|
<Carousel items={this.state.featuredCustom.custom_projects_loved_by_following} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.state.featuredCustom.custom_projects_in_studios_following) {
|
|
|
|
rows.push(
|
|
|
|
<Box title="Projects in Studios I'm Following" key="custom_projects_in_studios_following">
|
|
|
|
<Carousel items={this.state.featuredCustom.custom_projects_in_studios_following} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
rows.push(
|
|
|
|
<Box title="What the Community is Remixing" key="community_most_remixed_projects">
|
|
|
|
<Carousel items={this.state.featuredGlobal.community_most_remixed_projects} showRemixes={true} />
|
|
|
|
</Box>,
|
|
|
|
<Box title="What the Community is Loving" key="community_most_loved_projects">
|
|
|
|
<Carousel items={this.state.featuredGlobal.community_most_loved_projects} showLoves={true} />
|
|
|
|
</Box>
|
|
|
|
);
|
|
|
|
|
|
|
|
return rows;
|
|
|
|
},
|
2015-09-02 15:08:58 -04:00
|
|
|
render: function () {
|
2015-10-20 13:18:57 -04:00
|
|
|
var featured = this.renderHomepageRows();
|
2015-09-02 15:08:58 -04:00
|
|
|
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-10-20 12:25:30 -04:00
|
|
|
<Activity items={this.state.activity} />
|
2015-10-07 16:23:08 -04:00
|
|
|
<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-10-20 13:18:57 -04:00
|
|
|
|
|
|
|
{featured}
|
|
|
|
|
2015-10-19 14:15:56 -04:00
|
|
|
<AdminPanel>
|
|
|
|
<dt>Tools</dt>
|
|
|
|
<dd>
|
|
|
|
<ul>
|
|
|
|
<li>
|
|
|
|
<a href="/scratch_admin/tickets">Ticket Queue</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="/scratch_admin/ip-search/">IP Search</a>
|
|
|
|
</li>
|
|
|
|
<li>
|
|
|
|
<a href="/scratch_admin/email-search/">Email Search</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</dd>
|
|
|
|
<dt>Homepage Cache</dt>
|
|
|
|
<dd>
|
|
|
|
<ul className="cache-list">
|
|
|
|
<li>
|
|
|
|
<form
|
|
|
|
id="homepage-refresh-form"
|
|
|
|
method="post"
|
|
|
|
action="/scratch_admin/homepage/clear-cache/">
|
|
|
|
|
|
|
|
<div className="button-row">
|
|
|
|
<span>Refresh row data:</span>
|
|
|
|
<Button type="submit">
|
|
|
|
<span>Refresh</span>
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</dd>
|
|
|
|
</AdminPanel>
|
2015-09-02 15:08:58 -04:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-10-16 15:10:17 -04:00
|
|
|
render(<Splash />, document.getElementById('view'));
|