From 35439cb82d185d1117bfc9ff2e49aaf8b73cb76f Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Tue, 27 Jun 2017 09:37:33 +1200 Subject: [PATCH] Removing placeholder elements in favor of loader - simpler is better --- src/js/views/Playlist.js | 96 +++++++++++++--------------------- src/js/views/User.js | 108 +++++++++++++++++++-------------------- 2 files changed, 88 insertions(+), 116 deletions(-) diff --git a/src/js/views/Playlist.js b/src/js/views/Playlist.js index 3f6fb33e..411ce934 100755 --- a/src/js/views/Playlist.js +++ b/src/js/views/Playlist.js @@ -141,9 +141,11 @@ class Playlist extends React.Component{ } render(){ + if (!this.props.playlist) return null var scheme = helpers.uriSource( this.props.params.uri ) var context = 'playlist' + if (this.props.playlist.can_edit) context = 'editable-playlist' var user_id = helpers.getFromUri('userid',this.props.params.uri) var playlist_id = helpers.getFromUri('playlistid',this.props.params.uri) @@ -155,70 +157,44 @@ class Playlist extends React.Component{ ) } - if (this.props.playlist){ - if (this.props.playlist.can_edit) context = 'editable-playlist' + return ( +
+ + - return ( -
- - - -
- -
- -
-

{ this.props.playlist.name }

- { this.props.playlist.description ?

: null } - -
    -
  • - - - {helpers.uriSource( this.props.params.uri )} playlist - -
  • - { this.props.playlist.owner ?
  • {this.props.playlist.owner.id}
  • : null } - { this.props.playlist.followers ?
  • {this.props.playlist.followers.total.toLocaleString()} followers
  • : null } - { this.props.playlist.last_modified ?
  • : null } -
  • - { this.props.playlist.tracks_total ? this.props.playlist.tracks_total : '0'} tracks,  - { this.props.playlist.tracks ? : '0 mins' } -
  • -
-
- - { this.renderActions() } - -
- { this.props.playlist.tracks ? this.removeTracks(tracks_indexes) } reorderTracks={ (indexes, index) => this.reorderTracks(indexes, index) } /> : null } - this.loadMore() }/> -
+
+
- ) - } else { - return ( -
- - -
-
- Playlist -
-

-
    -
  • - -
  • -
-
-
- -
+
+

{ this.props.playlist.name }

+ { this.props.playlist.description ?

: null } + +
    +
  • + + + {helpers.uriSource( this.props.params.uri )} playlist + +
  • + { this.props.playlist.owner ?
  • {this.props.playlist.owner.id}
  • : null } + { this.props.playlist.followers ?
  • {this.props.playlist.followers.total.toLocaleString()} followers
  • : null } + { this.props.playlist.last_modified ?
  • : null } +
  • + { this.props.playlist.tracks_total ? this.props.playlist.tracks_total : '0'} tracks,  + { this.props.playlist.tracks ? : '0 mins' } +
  • +
- ) - } + + { this.renderActions() } + +
+ { this.props.playlist.tracks ? this.removeTracks(tracks_indexes) } reorderTracks={ (indexes, index) => this.reorderTracks(indexes, index) } /> : null } + this.loadMore() }/> +
+
+ ) } } diff --git a/src/js/views/User.js b/src/js/views/User.js index f2ba7f2a..67f597e0 100755 --- a/src/js/views/User.js +++ b/src/js/views/User.js @@ -44,75 +44,71 @@ class User extends React.Component{ } render(){ - 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]) - } - } - } - - if (this.props.user && this.props.user.images ){ - var image = helpers.sizedImages(this.props.user.images).huge - } else { - var image = null - } - + var user_id = helpers.getFromUri('userid',this.props.params.uri) + if (helpers.isLoading(this.props.load_queue,['spotify_users/'+user_id,'spotify_users/'+user_id+'/playlists/?'])){ return ( -
- - - -
- -
- -

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

-

-
    -
  • {this.props.user.playlists_total ? this.props.user.playlists_total.toLocaleString() : 0} playlists
  • -
  • {this.props.user.followers.total.toLocaleString()} followers
  • - {this.isMe() ?
  • You
  • : null} -
-

-
- -
-
-
- -
-
-

Playlists

- - this.loadMore() }/> -
-
+
+
) - } else { + } - return ( -
-
- -

+ 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 && this.props.user.images ){ + var image = helpers.sizedImages(this.props.user.images).huge + } else { + var image = null + } + + return ( +
+ + + +
+ +
+ +

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

+

+
    +
  • {this.props.user.playlists_total ? this.props.user.playlists_total.toLocaleString() : 0} playlists
  • +
  • {this.props.user.followers.total.toLocaleString()} followers
  • + {this.isMe() ?
  • You
  • : null} +
+

- +
- ); - } - + +
+
+

Playlists

+ + this.loadMore() }/> +
+
+
+ ) } } const mapStateToProps = (state, ownProps) => { return { + load_queue: state.ui.load_queue, spotify_authorized: state.spotify.authorized, me: state.spotify.me, playlists: state.ui.playlists,