From 0db7a9213063b8c0135383415930ce2841059873 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Thu, 23 Mar 2017 21:20:25 +1300 Subject: [PATCH] Frontend filtering, no album/artist/playlist results --- src/js/components/DropdownField.js | 4 +-- src/js/views/Search.js | 42 +++++++++++++++++++++--------- 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/js/components/DropdownField.js b/src/js/components/DropdownField.js index 867a76cb..74e42cbe 100755 --- a/src/js/components/DropdownField.js +++ b/src/js/components/DropdownField.js @@ -60,8 +60,8 @@ export default class DropdownField extends React.Component{ return (
this.handleToggle() }> - -   { this.props.name } + {this.props.icon ?   : null} + { this.props.name }
{ diff --git a/src/js/views/Search.js b/src/js/views/Search.js index 5014ea71..e36da71c 100755 --- a/src/js/views/Search.js +++ b/src/js/views/Search.js @@ -14,6 +14,7 @@ import AlbumGrid from '../components/AlbumGrid' import PlaylistGrid from '../components/PlaylistGrid' import LazyLoadListener from '../components/LazyLoadListener' +import * as helpers from '../helpers' import * as uiActions from '../services/ui/actions' import * as mopidyActions from '../services/mopidy/actions' import * as spotifyActions from '../services/spotify/actions' @@ -61,12 +62,14 @@ class Search extends React.Component{ } renderResults(){ + var type = (this.props.params.type ? this.props.params.type : 'all') + var source = (this.props.params.source ? this.props.params.source : 'all') var artists = [] if (this.props.artists_uris){ for (var i = 0; i < this.props.artists_uris.length; i++){ var uri = this.props.artists_uris[i] - if (this.props.artists.hasOwnProperty(uri)){ + if (this.props.artists.hasOwnProperty(uri) && (source == 'all' || helpers.uriSource(uri) == source)){ artists.push(this.props.artists[uri]) } } @@ -76,7 +79,7 @@ class Search extends React.Component{ if (this.props.albums_uris){ for (var i = 0; i < this.props.albums_uris.length; i++){ var uri = this.props.albums_uris[i] - if (this.props.albums.hasOwnProperty(uri)){ + if (this.props.albums.hasOwnProperty(uri) && (source == 'all' || helpers.uriSource(uri) == source)){ albums.push(this.props.albums[uri]) } } @@ -86,20 +89,33 @@ class Search extends React.Component{ if (this.props.playlists_uris){ for (var i = 0; i < this.props.playlists_uris.length; i++){ var uri = this.props.playlists_uris[i] - if (this.props.playlists.hasOwnProperty(uri)){ + if (this.props.playlists.hasOwnProperty(uri) && (source == 'all' || helpers.uriSource(uri) == source)){ playlists.push(this.props.playlists[uri]) } } } - switch( this.props.params.type ){ + var tracks = [] + if (this.props.tracks){ + if (source == 'all'){ + tracks = this.props.tracks + } else { + for (var i = 0; i < this.props.tracks.length; i++){ + if (helpers.uriSource(this.props.tracks[i].uri) == source){ + tracks.push(this.props.tracks[i]) + } + } + } + } + + switch( type ){ case 'artists': return (
- this.loadMore('artists') }/> + this.loadMore('artists') }/>
) @@ -110,7 +126,7 @@ class Search extends React.Component{
- this.loadMore('albums') }/> + this.loadMore('albums') }/>
) @@ -121,7 +137,7 @@ class Search extends React.Component{
- this.loadMore('playlists') }/> + this.loadMore('playlists') }/>
) @@ -131,8 +147,8 @@ class Search extends React.Component{ return (
- - this.loadMore('tracks') }/> + + this.loadMore('tracks') }/>
) @@ -164,8 +180,8 @@ class Search extends React.Component{

Tracks

- - this.loadMore('tracks') }/> + + this.loadMore('tracks') }/>
@@ -229,8 +245,8 @@ class Search extends React.Component{ var options = ( - this.handleTypeChange(val)} /> - this.handleSourceChange(val)} /> + this.handleTypeChange(val)} /> + this.handleSourceChange(val)} /> )