mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2024-11-27 01:25:52 -05:00
Merge pull request #668 from mewtaylor/issue/gh-666-all
Fix GH-666: Make category options into key/value
This commit is contained in:
commit
20b472f66d
1 changed files with 32 additions and 32 deletions
|
@ -1,3 +1,4 @@
|
|||
var classNames = require('classnames');
|
||||
var injectIntl = require('react-intl').injectIntl;
|
||||
var FormattedMessage = require('react-intl').FormattedMessage;
|
||||
var React = require('react');
|
||||
|
@ -17,7 +18,14 @@ require('./explore.scss');
|
|||
var Explore = injectIntl(React.createClass({
|
||||
type: 'Explore',
|
||||
getDefaultProps: function () {
|
||||
var categoryOptions = ['all','animations','art','games','music','stories'];
|
||||
var categoryOptions = {
|
||||
all: '*',
|
||||
animations: 'animations',
|
||||
art: 'art',
|
||||
games: 'games',
|
||||
music: 'music',
|
||||
stories: 'stories'
|
||||
};
|
||||
var typeOptions = ['projects','studios'];
|
||||
|
||||
var pathname = window.location.pathname.toLowerCase();
|
||||
|
@ -28,7 +36,7 @@ var Explore = injectIntl(React.createClass({
|
|||
var currentCategory = pathname.substring(slash + 1,pathname.length);
|
||||
var typeStart = pathname.indexOf('explore/');
|
||||
var type = pathname.substring(typeStart + 8,slash);
|
||||
if (categoryOptions.indexOf(currentCategory) === -1 || typeOptions.indexOf(type) === -1) {
|
||||
if (Object.keys(categoryOptions).indexOf(currentCategory) === -1 || typeOptions.indexOf(type) === -1) {
|
||||
window.location = window.location.origin + '/explore/projects/all/';
|
||||
}
|
||||
|
||||
|
@ -50,10 +58,8 @@ var Explore = injectIntl(React.createClass({
|
|||
this.getExploreMore();
|
||||
},
|
||||
getExploreMore: function () {
|
||||
var qText = '';
|
||||
if (this.props.tab != 'all') {
|
||||
qText = '&q=' + this.props.category;
|
||||
}
|
||||
var qText = '&q=' + this.props.acceptableTabs[this.props.category] || '*';
|
||||
|
||||
api({
|
||||
uri: '/search/' + this.props.itemType +
|
||||
'?limit=' + this.props.loadNumber +
|
||||
|
@ -80,34 +86,28 @@ var Explore = injectIntl(React.createClass({
|
|||
window.location = window.location.origin + '/explore/' + newType + '/' + this.props.tab;
|
||||
},
|
||||
getBubble: function (type) {
|
||||
var allBubble = <a href={'/explore/' + this.props.itemType + '/' + type + '/'}>
|
||||
<li>
|
||||
<FormattedMessage id={'general.' + type} />
|
||||
</li>
|
||||
</a>;
|
||||
if (this.props.category === type) {
|
||||
allBubble = <a href={'/explore/' + this.props.itemType+'/' + type + '/'}>
|
||||
<li className='active'>
|
||||
<FormattedMessage id={'general.' + type} />
|
||||
</li>
|
||||
</a>;
|
||||
}
|
||||
return allBubble;
|
||||
let classes = classNames({
|
||||
active: (this.props.category === type)
|
||||
});
|
||||
return (
|
||||
<a href={'/explore/' + this.props.itemType + '/' + type + '/'}>
|
||||
<li className={classes}>
|
||||
<FormattedMessage id={'general.' + type} />
|
||||
</li>
|
||||
</a>
|
||||
);
|
||||
},
|
||||
getTab: function (type) {
|
||||
var allTab = <a href={'/explore/' + type + '/' + this.props.category + '/'}>
|
||||
<li>
|
||||
<FormattedMessage id={'general.' + type} />
|
||||
</li>
|
||||
</a>;
|
||||
if (this.props.itemType === type) {
|
||||
allTab = <a href={'/explore/' + type +' /' + this.props.category + '/'}>
|
||||
<li className='active'>
|
||||
<FormattedMessage id={'general.' + type} />
|
||||
</li>
|
||||
</a>;
|
||||
}
|
||||
return allTab;
|
||||
let classes = classNames({
|
||||
active: (this.props.itemType === type)
|
||||
});
|
||||
return (
|
||||
<a href={'/explore/' + type + '/' + this.props.category + '/'}>
|
||||
<li className={classes}>
|
||||
<FormattedMessage id={'general.' + type} />
|
||||
</li>
|
||||
</a>
|
||||
);
|
||||
},
|
||||
render: function () {
|
||||
return (
|
||||
|
|
Loading…
Reference in a new issue