Moving search context to URI component

This commit is contained in:
James Barnsley
2018-01-05 21:31:59 +13:00
parent 90eda428c2
commit 910f03a8c8
7 changed files with 134 additions and 76 deletions

View File

@ -21,14 +21,14 @@ class SearchForm extends React.Component{
componentDidMount(){
if (this.props.query){
this.setState({query: this.props.query})
var query = this.props.query.replace("search:","");
this.setState({query: query});
}
}
componentWillReceiveProps(newProps){
if (newProps.query && newProps.query != this.state.query && !this.state.in_focus){
this.setState({query: newProps.query});
console.log(newProps.query);
this.setState({query: newProps.query.replace("search:","")});
}
}
@ -51,7 +51,21 @@ class SearchForm extends React.Component{
break
default:
hashHistory.push(global.baseURL+'search/search:'+this.props.view+':'+encodeURIComponent(this.state.query));
var available_views = ["artist","album","playlist","track"];
var view_defined = false;
var query = this.state.query;
for (var i = 0; i < available_views.length; i++){
if (query.startsWith(available_views[i]+':')){
view_defined = true;
}
}
if (!view_defined){
query = "all:"+query;
}
hashHistory.push(global.baseURL+'search/search:'+query);
break
}