From 6156b06a0aa9d9959dca10f28606531dcd044126 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Sun, 26 Feb 2017 18:33:20 +1300 Subject: [PATCH] More general detection for uri type --- src/js/helpers.js | 54 +++++++++++++++------- src/js/views/Album.js | 4 +- src/js/views/Artist.js | 2 +- src/js/views/Playlist.js | 2 +- src/js/views/User.js | 91 +++++++++++++++++++++++++------------- src/scss/global/_core.scss | 5 +++ 6 files changed, 109 insertions(+), 49 deletions(-) diff --git a/src/js/helpers.js b/src/js/helpers.js index 2505b232..83db124a 100755 --- a/src/js/helpers.js +++ b/src/js/helpers.js @@ -158,23 +158,47 @@ export let sourceIcon = function(uri,source = null){ **/ export let getFromUri = function(element,uri){ var exploded = uri.split(':'); + var namespace = exploded[0] - if( element == 'mbid'){ - var index = exploded.indexOf('mbid') - if( index > -1 ) return exploded[index+1] + switch (element){ + case 'mbid': + var index = exploded.indexOf('mbid') + if( index > -1 ) return exploded[index+1] + break + + case 'artistid': + if (exploded[1] == 'artist'){ + return exploded[2] + } + break + + case 'albumid': + if (exploded[1] == 'album'){ + return exploded[2] + } + break + + case 'playlistid': + if (exploded[1] == 'playlist'){ + return exploded[2] + } else if (exploded[1] == 'user' && exploded[3] == 'playlist'){ + return exploded[4] + } + break + + case 'trackid': + if (exploded[1] == 'track'){ + return exploded[2] + } + break + + case 'userid': + if (exploded[1] == 'user'){ + return exploded[2] + } + break } - - if( exploded[0] == 'spotify' ){ - if( element == 'userid' && exploded[1] == 'user' ) return exploded[2]; - if( element == 'playlistid' && exploded[3] == 'playlist' ) return exploded[4]; - if( element == 'artistid' && exploded[1] == 'artist' ) return exploded[2]; - if( element == 'artistid' && exploded[3] == 'playlist' ) return exploded[2]; - if( element == 'albumid' && exploded[1] == 'album' ) return exploded[2]; - if( element == 'trackid' && exploded[1] == 'track' ) return exploded[2]; - return null; - } - - return null + return null } /** diff --git a/src/js/views/Album.js b/src/js/views/Album.js index c7a08044..640d0eee 100755 --- a/src/js/views/Album.js +++ b/src/js/views/Album.js @@ -43,7 +43,7 @@ class Album extends React.Component{ // if mopidy has just connected AND we're a local album, go get }else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){ - if( helpers.uriSource( this.props.params.uri ) == 'local' ){ + if( helpers.uriSource( this.props.params.uri ) != 'spotify' ){ this.loadAlbum( nextProps ) } } @@ -56,6 +56,7 @@ class Album extends React.Component{ if (props.album && props.album.tracks && props.album.artists_uris){ console.info('Loading album from index') }else{ + console.log(props.params.uri) this.props.spotifyActions.getAlbum( props.params.uri ); } break; @@ -91,6 +92,7 @@ class Album extends React.Component{ } } } + return (
diff --git a/src/js/views/Artist.js b/src/js/views/Artist.js index e8daa026..b7904de6 100755 --- a/src/js/views/Artist.js +++ b/src/js/views/Artist.js @@ -40,7 +40,7 @@ class Artist extends React.Component{ if( nextProps.params.uri != this.props.params.uri ){ this.loadArtist( nextProps ) }else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){ - if( helpers.uriSource( this.props.params.uri ) == 'local' ){ + if( helpers.uriSource( this.props.params.uri ) != 'spotify' ){ this.loadArtist( nextProps ) } } diff --git a/src/js/views/Playlist.js b/src/js/views/Playlist.js index 0d2c3e83..fef4e085 100755 --- a/src/js/views/Playlist.js +++ b/src/js/views/Playlist.js @@ -33,7 +33,7 @@ class Playlist extends React.Component{ if( nextProps.params.uri != this.props.params.uri ){ this.loadPlaylist( nextProps ) }else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){ - if( helpers.uriSource( this.props.params.uri ) == 'm3u' ){ + if( helpers.uriSource( this.props.params.uri ) != 'spotify' ){ this.loadPlaylist( nextProps ) } } diff --git a/src/js/views/User.js b/src/js/views/User.js index 81204c03..f425781d 100755 --- a/src/js/views/User.js +++ b/src/js/views/User.js @@ -42,48 +42,77 @@ class User extends React.Component{ } render(){ - if( !this.props.user ) return null - - var playlists = [] - if (this.props.user.playlists_uris){ - for (var i = 0; i < this.props.user.playlists_uris.length; i++){ - var uri = this.props.user.playlists_uris[i] - if (this.props.playlists.hasOwnProperty(uri)){ - playlists.push(this.props.playlists[uri]) + if (this.props.user){ + var playlists = [] + if (this.props.user.playlists_uris){ + for (var i = 0; i < this.props.user.playlists_uris.length; i++){ + var uri = this.props.user.playlists_uris[i] + if (this.props.playlists.hasOwnProperty(uri)){ + playlists.push(this.props.playlists[uri]) + } } } - } - return ( -
- -
+ return ( +
+ +
-
- +
+ -

{ this.props.user.display_name ? this.props.user.display_name : this.props.user.id }

+

{ this.props.user.display_name ? this.props.user.display_name : this.props.user.id }

-
    - {this.isMe() ?
  • You
  • : null} -
  • {this.props.user.playlists_total ? this.props.user.playlists_total.toLocaleString() : 0} playlists
  • -
  • {this.props.user.followers.total.toLocaleString()} followers
  • -
+
    + {this.isMe() ?
  • You
  • : null} +
  • {this.props.user.playlists_total ? this.props.user.playlists_total.toLocaleString() : 0} playlists
  • +
  • {this.props.user.followers.total.toLocaleString()} followers
  • +
-
- +
+ +
+
+
+ +
+ + this.loadMore() }/> +
+
-
+ ) + } else { -
- - this.loadMore() }/> -
- + return ( +
+
+
+ +

+
    +
  • + +
  • +
+
+ +
+
+
+
+
+ + + +
+
+
-
- ); + ); + } + } } diff --git a/src/scss/global/_core.scss b/src/scss/global/_core.scss index e5b46013..dc9c2af0 100755 --- a/src/scss/global/_core.scss +++ b/src/scss/global/_core.scss @@ -141,6 +141,11 @@ button.placeholder { width: auto; margin: 25px 40px; height: 10px; + + @include responsive( $bp_medium ){ + margin-left: 20px; + margin-right: 20px; + } } .grid-wrapper .placeholder {