From 3ebe44f86a5d84d6471ddaeb7531eaf5f74f09b9 Mon Sep 17 00:00:00 2001 From: kyleplo <31634240+kyleplo@users.noreply.github.com> Date: Fri, 27 Jul 2018 12:06:06 -0400 Subject: [PATCH 01/16] Add css for dropdown --- src/views/search/search.scss | 39 +++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/views/search/search.scss b/src/views/search/search.scss index 2588ac6ef..fa93c50a1 100644 --- a/src/views/search/search.scss +++ b/src/views/search/search.scss @@ -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 { - select { - margin-bottom: 0; - color: $header-gray; - } + .sort-controls { + display: flex; + margin: 0 auto; + border-bottom: 1px solid $ui-border; + padding: 8px 0; + width: 58.75rem; + justify-content: space-between; + } - .help-block { - display: none; + .sort-mode { + 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; + } } } From 539cfa5bcdab89a4e25fa0edc9f0e2175da1d4c2 Mon Sep 17 00:00:00 2001 From: kyleplo <31634240+kyleplo@users.noreply.github.com> Date: Fri, 27 Jul 2018 12:54:59 -0400 Subject: [PATCH 02/16] Add filter mode dropdown --- src/views/search/search.jsx | 53 ++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/src/views/search/search.jsx b/src/views/search/search.jsx index d9fd1655a..092dae2f9 100644 --- a/src/views/search/search.jsx +++ b/src/views/search/search.jsx @@ -8,6 +8,7 @@ const React = require('react'); const api = require('../../lib/api'); const Button = require('../../components/forms/button.jsx'); +const Form = require('../../components/forms/form.jsx'); const Grid = require('../../components/grid/grid.jsx'); const navigationActions = require('../../redux/navigation.js'); const TitleBanner = require('../../components/title-banner/title-banner.jsx'); @@ -23,12 +24,14 @@ class Search extends React.Component { super(props); bindAll(this, [ 'getSearchState', + 'handleChangeSortMode', 'handleGetSearchMore', 'getTab' ]); this.state = this.getSearchState(); this.state.loaded = []; this.state.loadNumber = 16; + this.state.mode = ''; this.state.offset = 0; this.state.loadMore = false; } @@ -47,6 +50,20 @@ class Search extends React.Component { } term = decodeURIComponent(term.split('+').join(' ')); this.props.dispatch(navigationActions.setSearchTerm(term)); + + let mode = ''; + const m = query.lastIndexOf('m='); + if (m !== -1) { + mode = query.substring(m + 2, query.length).toLowerCase(); + } + while (mode.indexOf('/') > -1) { + mode = mode.substring(0, term.indexOf('/')); + } + while (term.indexOf('&') > -1) { + mode = mode.substring(0, term.indexOf('&')); + } + mode = decodeURIComponent(mode.split('+').join(' ')); + this.state.mode = mode; } componentDidUpdate (prevProps) { if (this.props.searchTerm !== prevProps.searchTerm) { @@ -60,11 +77,20 @@ class Search extends React.Component { } const start = pathname.lastIndexOf('/'); const type = pathname.substring(start + 1, pathname.length); + const modeOptions = ['trending', 'popular', 'recent', '']; return { + acceptableModes: modeOptions, tab: type, loadNumber: 16 }; } + handleChangeSortMode (name, value) { + if (this.state.acceptableModes.indexOf(value) !== -1) { + const term = this.props.searchTerm.split(' ').join('+'); + window.location = + `${window.location.origin}/search/${this.state.tab}?q=${term}&m=${value}`; + } + } handleGetSearchMore () { let termText = ''; if (this.props.searchTerm !== '') { @@ -73,7 +99,8 @@ class Search extends React.Component { const locale = this.props.intl.locale; const loadNumber = this.state.loadNumber; 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({ uri: `/search/${this.state.tab}?${queryString}` @@ -167,6 +194,29 @@ class Search extends React.Component { {this.getTab('projects')} {this.getTab('studios')} +
+
+