Commit aa3cbe55 authored by Matthew Taylor's avatar Matthew Taylor

Make category options into key/value

so that we can store the query string with the tab name, since it's not the same in every instance. fixes #666, and makes a couple other style tweaks.
parent 11155c42
var classNames = require('classnames');
var injectIntl = require('react-intl').injectIntl; var injectIntl = require('react-intl').injectIntl;
var FormattedMessage = require('react-intl').FormattedMessage; var FormattedMessage = require('react-intl').FormattedMessage;
var React = require('react'); var React = require('react');
...@@ -17,7 +18,14 @@ require('./explore.scss'); ...@@ -17,7 +18,14 @@ require('./explore.scss');
var Explore = injectIntl(React.createClass({ var Explore = injectIntl(React.createClass({
type: 'Explore', type: 'Explore',
getDefaultProps: function () { 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 typeOptions = ['projects','studios'];
var pathname = window.location.pathname.toLowerCase(); var pathname = window.location.pathname.toLowerCase();
...@@ -28,7 +36,7 @@ var Explore = injectIntl(React.createClass({ ...@@ -28,7 +36,7 @@ var Explore = injectIntl(React.createClass({
var currentCategory = pathname.substring(slash + 1,pathname.length); var currentCategory = pathname.substring(slash + 1,pathname.length);
var typeStart = pathname.indexOf('explore/'); var typeStart = pathname.indexOf('explore/');
var type = pathname.substring(typeStart + 8,slash); 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/'; window.location = window.location.origin + '/explore/projects/all/';
} }
...@@ -50,10 +58,8 @@ var Explore = injectIntl(React.createClass({ ...@@ -50,10 +58,8 @@ var Explore = injectIntl(React.createClass({
this.getExploreMore(); this.getExploreMore();
}, },
getExploreMore: function () { getExploreMore: function () {
var qText = ''; var qText = '&q=' + this.props.acceptableTabs[this.props.category] || '*';
if (this.props.tab != 'all') {
qText = '&q=' + this.props.category;
}
api({ api({
uri: '/search/' + this.props.itemType + uri: '/search/' + this.props.itemType +
'?limit=' + this.props.loadNumber + '?limit=' + this.props.loadNumber +
...@@ -80,34 +86,28 @@ var Explore = injectIntl(React.createClass({ ...@@ -80,34 +86,28 @@ var Explore = injectIntl(React.createClass({
window.location = window.location.origin + '/explore/' + newType + '/' + this.props.tab; window.location = window.location.origin + '/explore/' + newType + '/' + this.props.tab;
}, },
getBubble: function (type) { getBubble: function (type) {
var allBubble = <a href={'/explore/' + this.props.itemType + '/' + type + '/'}> let classes = classNames({
<li> active: (this.props.category === type)
<FormattedMessage id={'general.' + type} /> });
</li> return (
</a>; <a href={'/explore/' + this.props.itemType + '/' + type + '/'}>
if (this.props.category === type) { <li className={classes}>
allBubble = <a href={'/explore/' + this.props.itemType+'/' + type + '/'}> <FormattedMessage id={'general.' + type} />
<li className='active'> </li>
<FormattedMessage id={'general.' + type} /> </a>
</li> );
</a>;
}
return allBubble;
}, },
getTab: function (type) { getTab: function (type) {
var allTab = <a href={'/explore/' + type + '/' + this.props.category + '/'}> let classes = classNames({
<li> active: (this.props.itemType === type)
<FormattedMessage id={'general.' + type} /> });
</li> return (
</a>; <a href={'/explore/' + type + '/' + this.props.category + '/'}>
if (this.props.itemType === type) { <li className={classes}>
allTab = <a href={'/explore/' + type +' /' + this.props.category + '/'}> <FormattedMessage id={'general.' + type} />
<li className='active'> </li>
<FormattedMessage id={'general.' + type} /> </a>
</li> );
</a>;
}
return allTab;
}, },
render: function () { render: function () {
return ( return (
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment