diff --git a/src/js/components/SearchForm.js b/src/js/components/SearchForm.js
index 851fef88..95678c7b 100755
--- a/src/js/components/SearchForm.js
+++ b/src/js/components/SearchForm.js
@@ -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
}
diff --git a/src/js/helpers.js b/src/js/helpers.js
index 8336854d..29bfcaf7 100755
--- a/src/js/helpers.js
+++ b/src/js/helpers.js
@@ -380,7 +380,7 @@ export let sourceIcon = function(uri,source = null){
* @param element = string, the element we wish to extract
* @param uri = string
**/
-export let getFromUri = function(element,uri){
+export let getFromUri = function(element, uri = ""){
var exploded = uri.split(':');
var namespace = exploded[0]
@@ -439,6 +439,22 @@ export let getFromUri = function(element,uri){
return exploded[2]
}
break
+
+ case 'searchcontext':
+ if (exploded[0] == "search"){
+ var available_views = ["all","artist","album","playlist","track"];
+ var view = available_views.indexOf(exploded[1]);
+ if (view > -1){
+ return exploded[1];
+ }
+ }
+ break
+
+ case 'searchterm':
+ if (exploded[0] == "search"){
+ return exploded[2];
+ }
+ break
}
return null
}
diff --git a/src/js/index.js b/src/js/index.js
index 6d821bbb..81c374d8 100755
--- a/src/js/index.js
+++ b/src/js/index.js
@@ -67,7 +67,7 @@ ReactDOM.render(
-
+
diff --git a/src/js/views/Artist.js b/src/js/views/Artist.js
index 8193011b..1e1acfa1 100755
--- a/src/js/views/Artist.js
+++ b/src/js/views/Artist.js
@@ -218,7 +218,7 @@ class Artist extends React.Component{
- {related_artists.length > 0 ? Related artists
All related artists
: null}
+ {related_artists.length > 0 ? Related artists
All related artists
: null}
diff --git a/src/js/views/Search.js b/src/js/views/Search.js
index 7453ef42..aa8c4424 100755
--- a/src/js/views/Search.js
+++ b/src/js/views/Search.js
@@ -29,63 +29,64 @@ class Search extends React.Component{
}
componentDidMount(){
- var view = 'all';
- if (this.props.params && this.props.params.view){
- view = this.props.params.view;
- }
-
- var query = false;
+ var context = "all";
+ var term = null;
if (this.props.params && this.props.params.query && this.props.params.query !== ''){
- query = this.props.params.query;
+ context = helpers.getFromUri("searchcontext",this.props.params.query);
+ term = helpers.getFromUri("searchterm",this.props.params.query);
}
// Auto-focus on the input field
- //$(document).find('.search-form input').focus();
+ $(document).find('.search-form input').focus();
- if (query){
+ if (context && term){
if (this.props.mopidy_connected && this.props.search_uri_schemes){
- this.props.mopidyActions.getSearchResults(view, query)
+ this.props.mopidyActions.getSearchResults(context, term)
}
if (this.props.spotify_connected && this.props.search_uri_schemes && this.props.search_uri_schemes.includes('spotify:')){
- this.props.spotifyActions.getSearchResults(view, query)
+ this.props.spotifyActions.getSearchResults(context, term)
}
}
}
componentWillReceiveProps(newProps){
- if (newProps.params && newProps.params.view){
- var view = newProps.params.view;
+ if (this.props.params && this.props.params.query && this.props.params.query !== ''){
+ var old_context = helpers.getFromUri("searchcontext",this.props.params.query);
+ var old_term = helpers.getFromUri("searchterm",this.props.params.query);
} else {
- var view = 'all';
+ var old_context = "all";
+ var old_term = null;
}
if (newProps.params && newProps.params.query && newProps.params.query !== ''){
- var query = newProps.params.query;
+ var context = helpers.getFromUri("searchcontext",newProps.params.query);
+ var term = helpers.getFromUri("searchterm",newProps.params.query);
} else {
- var query = null;
+ var context = "all";
+ var term = null;
}
- if (query && !this.props.mopidy_connected && newProps.mopidy_connected){
- this.props.mopidyActions.getSearchResults(view, query)
+ if (term && !this.props.mopidy_connected && newProps.mopidy_connected){
+ this.props.mopidyActions.getSearchResults(context, term);
}
- if (query && !this.props.spotify_connected && newProps.spotify_connected && newProps.search_uri_schemes.includes('spotify:')){
- this.props.spotifyActions.getSearchResults(view, query)
+ if (term && !this.props.spotify_connected && newProps.spotify_connected && newProps.search_uri_schemes.includes('spotify:')){
+ this.props.spotifyActions.getSearchResults(context, term);
}
// Search changed
- if (query && query !== this.props.params.query){
+ if (term && context && term !== old_term){
this.props.mopidyActions.clearSearchResults();
this.props.spotifyActions.clearSearchResults();
if (this.props.mopidy_connected && this.props.search_uri_schemes){
- this.props.mopidyActions.getSearchResults(view, query)
+ this.props.mopidyActions.getSearchResults(context, term)
}
if (this.props.mopidy_connected && this.props.search_uri_schemes && this.props.search_uri_schemes.includes('spotify:')){
- this.props.spotifyActions.getSearchResults(view, query)
+ this.props.spotifyActions.getSearchResults(context, term)
}
}
}
@@ -108,6 +109,12 @@ class Search extends React.Component{
renderResults(){
+ var context = helpers.getFromUri("searchcontext",this.props.params.query);
+ var term = helpers.getFromUri("searchterm",this.props.params.query);
+ if (!context){
+ context = "all";
+ }
+
var spotify_search_enabled = (this.props.search_settings && this.props.search_settings.spotify);
if (this.props.sort == 'uri'){
@@ -152,16 +159,17 @@ class Search extends React.Component{
}
tracks = helpers.sortItems(tracks, this.props.sort, this.props.sort_reverse, sort_map);
- switch (this.props.params.view){
+ switch (context){
case 'artist':
return (
- Artists
-
- Back to all
+
+ Search
+
+ Artists
@@ -175,10 +183,11 @@ class Search extends React.Component{
return (
- Albums
-
- Back to all
+
+ Search
+
+ Albums
@@ -192,10 +201,11 @@ class Search extends React.Component{
return (
- Playlists
-
- Back to all
+
+ Search
+
+ Playlists
@@ -209,13 +219,14 @@ class Search extends React.Component{
return (
- Tracks
-
- Back to all
+
+ Search
+
+ Tracks
-
+
this.loadMore('tracks') }/>
@@ -228,14 +239,14 @@ class Search extends React.Component{
if (artists.length > 0){
var artists_section = (
-
-
- Artists
-
- More
-
-
-
+
+
+ Artists
+
+
+ {artists.length > 4 ?
+ All artists ({artists.length})
+ : null}
)
@@ -246,14 +257,14 @@ class Search extends React.Component{
if (albums.length > 0){
var albums_section = (
-
-
- Albums
-
- More
-
-
-
+
+
+ Albums
+
+
+ {albums.length > 4 ?
+ All albums ({albums.length})
+ : null}
)
@@ -264,14 +275,14 @@ class Search extends React.Component{
if (playlists.length > 0){
var playlists_section = (
-
-
- Playlists
-
- More
-
-
-
+
+
+ Playlists
+
+
+ {playlists.length > 4 ?
+ All playlists ({playlists.length})
+ : null}
)
@@ -282,8 +293,7 @@ class Search extends React.Component{
if (tracks.length > 0){
var tracks_section = (
- Tracks
-
+
this.loadMore('tracks') }/>
)
diff --git a/src/scss/global/_forms.scss b/src/scss/global/_forms.scss
index 26d69c5f..b429f151 100755
--- a/src/scss/global/_forms.scss
+++ b/src/scss/global/_forms.scss
@@ -112,6 +112,11 @@ input[type="submit"] {
background: $white;
}
+ &.grey {
+ color: $white;
+ background: $grey;
+ }
+
&.confirming,
&.destructive {
background: $red;
diff --git a/src/scss/views/_search.scss b/src/scss/views/_search.scss
index e3c95059..dd87f00c 100755
--- a/src/scss/views/_search.scss
+++ b/src/scss/views/_search.scss
@@ -15,7 +15,7 @@
font-weight: 700;
height: 3.1rem;
background: transparent;
- border-bottom: 2px solid transparent;
+ border-bottom: 2px solid $grey;
border-radius: 0;
/* handle Safari's ridiculous non-vertical centering */
@@ -31,12 +31,25 @@
}
}
- h4 {
- margin-bottom: 20px;
+ .search-result-sections {
+ padding-bottom: 30px;
- a {
- font-size: 14px;
- margin-left: 10px;
+ section {
+ width: 31%;
+ float: left;
+ margin-right: 3.5%;
+
+ &:last-child {
+ margin-right: 0;
+ }
+
+ .grid-item {
+ @include grid_item(2);
+
+ &:nth-child(1n+5){
+ display: none;
+ }
+ }
}
}