mirror of
https://github.com/scratchfoundation/scratch-www.git
synced 2025-02-19 19:07:47 -05:00
Merge pull request #2001 from kyleplo/patch-2
Add sort scheme dropdown to search results page
This commit is contained in:
commit
7851789f9f
3 changed files with 85 additions and 8 deletions
4
src/views/search/l10n.json
Normal file
4
src/views/search/l10n.json
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"search.trending": "Trending",
|
||||||
|
"search.popular": "Popular"
|
||||||
|
}
|
|
@ -8,14 +8,18 @@ const React = require('react');
|
||||||
|
|
||||||
const api = require('../../lib/api');
|
const api = require('../../lib/api');
|
||||||
const Button = require('../../components/forms/button.jsx');
|
const Button = require('../../components/forms/button.jsx');
|
||||||
|
const Form = require('../../components/forms/form.jsx');
|
||||||
const Grid = require('../../components/grid/grid.jsx');
|
const Grid = require('../../components/grid/grid.jsx');
|
||||||
const navigationActions = require('../../redux/navigation.js');
|
const navigationActions = require('../../redux/navigation.js');
|
||||||
|
const Select = require('../../components/forms/select.jsx');
|
||||||
const TitleBanner = require('../../components/title-banner/title-banner.jsx');
|
const TitleBanner = require('../../components/title-banner/title-banner.jsx');
|
||||||
const Tabs = require('../../components/tabs/tabs.jsx');
|
const Tabs = require('../../components/tabs/tabs.jsx');
|
||||||
|
|
||||||
const Page = require('../../components/page/www/page.jsx');
|
const Page = require('../../components/page/www/page.jsx');
|
||||||
const render = require('../../lib/render.jsx');
|
const render = require('../../lib/render.jsx');
|
||||||
|
|
||||||
|
const ACCEPTABLE_MODES = ['trending', 'popular', ''];
|
||||||
|
|
||||||
require('./search.scss');
|
require('./search.scss');
|
||||||
|
|
||||||
class Search extends React.Component {
|
class Search extends React.Component {
|
||||||
|
@ -23,14 +27,31 @@ class Search extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
bindAll(this, [
|
bindAll(this, [
|
||||||
'getSearchState',
|
'getSearchState',
|
||||||
|
'handleChangeSortMode',
|
||||||
'handleGetSearchMore',
|
'handleGetSearchMore',
|
||||||
'getTab'
|
'getTab'
|
||||||
]);
|
]);
|
||||||
this.state = this.getSearchState();
|
this.state = this.getSearchState();
|
||||||
this.state.loaded = [];
|
this.state.loaded = [];
|
||||||
this.state.loadNumber = 16;
|
this.state.loadNumber = 16;
|
||||||
|
this.state.mode = '';
|
||||||
this.state.offset = 0;
|
this.state.offset = 0;
|
||||||
this.state.loadMore = false;
|
this.state.loadMore = false;
|
||||||
|
|
||||||
|
let mode = '';
|
||||||
|
const query = window.location.search;
|
||||||
|
const m = query.lastIndexOf('mode=');
|
||||||
|
if (m !== -1) {
|
||||||
|
mode = query.substring(m + 5, query.length).toLowerCase();
|
||||||
|
}
|
||||||
|
while (mode.indexOf('/') > -1) {
|
||||||
|
mode = mode.substring(0, mode.indexOf('/'));
|
||||||
|
}
|
||||||
|
while (mode.indexOf('&') > -1) {
|
||||||
|
mode = mode.substring(0, mode.indexOf('&'));
|
||||||
|
}
|
||||||
|
mode = decodeURIComponent(mode.split('+').join(' '));
|
||||||
|
this.state.mode = mode;
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
const query = window.location.search;
|
const query = window.location.search;
|
||||||
|
@ -65,6 +86,13 @@ class Search extends React.Component {
|
||||||
loadNumber: 16
|
loadNumber: 16
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
handleChangeSortMode (name, value) {
|
||||||
|
if (ACCEPTABLE_MODES.indexOf(value) !== -1) {
|
||||||
|
const term = this.props.searchTerm.split(' ').join('+');
|
||||||
|
window.location =
|
||||||
|
`${window.location.origin}/search/${this.state.tab}?q=${term}&mode=${value}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
handleGetSearchMore () {
|
handleGetSearchMore () {
|
||||||
let termText = '';
|
let termText = '';
|
||||||
if (this.props.searchTerm !== '') {
|
if (this.props.searchTerm !== '') {
|
||||||
|
@ -73,7 +101,8 @@ class Search extends React.Component {
|
||||||
const locale = this.props.intl.locale;
|
const locale = this.props.intl.locale;
|
||||||
const loadNumber = this.state.loadNumber;
|
const loadNumber = this.state.loadNumber;
|
||||||
const offset = this.state.offset;
|
const offset = this.state.offset;
|
||||||
const queryString = `limit=${loadNumber}&offset=${offset}&language=${locale}&mode=popular${termText}`;
|
const mode = this.state.mode;
|
||||||
|
const queryString = `limit=${loadNumber}&offset=${offset}&language=${locale}&mode=${mode}${termText}`;
|
||||||
|
|
||||||
api({
|
api({
|
||||||
uri: `/search/${this.state.tab}?${queryString}`
|
uri: `/search/${this.state.tab}?${queryString}`
|
||||||
|
@ -167,6 +196,25 @@ class Search extends React.Component {
|
||||||
{this.getTab('projects')}
|
{this.getTab('projects')}
|
||||||
{this.getTab('studios')}
|
{this.getTab('studios')}
|
||||||
</Tabs>
|
</Tabs>
|
||||||
|
<div className="sort-controls">
|
||||||
|
<Form className="sort-mode">
|
||||||
|
<Select
|
||||||
|
name="sort"
|
||||||
|
options={[
|
||||||
|
{
|
||||||
|
value: 'trending',
|
||||||
|
label: this.props.intl.formatMessage({id: 'search.trending'})
|
||||||
|
},
|
||||||
|
{
|
||||||
|
value: 'popular',
|
||||||
|
label: this.props.intl.formatMessage({id: 'search.popular'})
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
value={this.state.mode}
|
||||||
|
onChange={this.handleChangeSortMode}
|
||||||
|
/>
|
||||||
|
</Form>
|
||||||
|
</div>
|
||||||
{this.getProjectBox()}
|
{this.getProjectBox()}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -104,15 +104,40 @@ $base-bg: $ui-white;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* HACK: sort controls are terrible. There's some sort of magic formula for height of formsy components that I can't control. */
|
||||||
|
|
||||||
.select {
|
.sort-controls {
|
||||||
select {
|
display: flex;
|
||||||
margin-bottom: 0;
|
margin: 0 auto;
|
||||||
color: $header-gray;
|
border-bottom: 1px solid $ui-border;
|
||||||
}
|
padding: 8px 0;
|
||||||
|
width: 58.75rem;
|
||||||
|
justify-content: space-between;
|
||||||
|
}
|
||||||
|
|
||||||
.help-block {
|
.sort-mode {
|
||||||
display: none;
|
margin-top: -4px;
|
||||||
|
width: 13.75rem;
|
||||||
|
|
||||||
|
.select {
|
||||||
|
|
||||||
|
select {
|
||||||
|
margin-bottom: 0;
|
||||||
|
border: 0;
|
||||||
|
background-color: transparent;
|
||||||
|
height: 32px;
|
||||||
|
color: $header-gray;
|
||||||
|
|
||||||
|
&:focus,
|
||||||
|
&:active {
|
||||||
|
background-color: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.help-block {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue