Commit 7b15ef23 authored by chrisgarrity's avatar chrisgarrity

Handle search queries

parent 404dc4b0
...@@ -29,6 +29,7 @@ class Search extends React.Component { ...@@ -29,6 +29,7 @@ class Search extends React.Component {
this.state = this.getSearchState(); this.state = this.getSearchState();
this.state.loaded = []; this.state.loaded = [];
this.state.loadNumber = 16; this.state.loadNumber = 16;
this.state.offset = 0;
} }
componentDidMount () { componentDidMount () {
const query = window.location.search; const query = window.location.search;
...@@ -48,7 +49,7 @@ class Search extends React.Component { ...@@ -48,7 +49,7 @@ class Search extends React.Component {
} }
componentDidUpdate (prevProps) { componentDidUpdate (prevProps) {
if (this.props.searchTerm !== prevProps.searchTerm) { if (this.props.searchTerm !== prevProps.searchTerm) {
this.getSearchMore(); this.handleGetSearchMore();
} }
} }
getSearchState () { getSearchState () {
...@@ -69,12 +70,12 @@ class Search extends React.Component { ...@@ -69,12 +70,12 @@ class Search extends React.Component {
termText = `&q=${encodeURIComponent(this.props.searchTerm.split(' ').join('+'))}`; termText = `&q=${encodeURIComponent(this.props.searchTerm.split(' ').join('+'))}`;
} }
const locale = this.props.intl.locale; const locale = this.props.intl.locale;
const loadNumber = this.props.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 queryString = `limit=${loadNumber}&offset=${offset}&language=${locale}&mode=popular${termText}`;
api({ api({
uri: `/search/${this.props.tab}?${queryString}` uri: `/search/${this.state.tab}?${queryString}`
}, (err, body) => { }, (err, body) => {
const loadedSoFar = this.state.loaded; const loadedSoFar = this.state.loaded;
Array.prototype.push.apply(loadedSoFar, body); Array.prototype.push.apply(loadedSoFar, body);
......
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