From 5b0a0b27b8c50f0b23c6b8ccdcf59857ba221370 Mon Sep 17 00:00:00 2001 From: James Barnsley Date: Wed, 1 Nov 2017 08:14:26 +1300 Subject: [PATCH] Moving follow check to asset, rather than component, fixes #146 --- src/js/components/FollowButton.js | 20 +++++++------------- src/js/views/Album.js | 5 +++-- src/js/views/Artist.js | 11 ++++++----- src/js/views/Playlist.js | 5 +++-- src/js/views/Track.js | 5 +++-- src/js/views/User.js | 15 +++++++++------ 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/js/components/FollowButton.js b/src/js/components/FollowButton.js index 59f0e642..99fed99f 100755 --- a/src/js/components/FollowButton.js +++ b/src/js/components/FollowButton.js @@ -12,38 +12,32 @@ import * as spotifyActions from '../services/spotify/actions' class FollowButton extends React.Component{ constructor(props){ - super(props) - } - - componentDidMount(){ - if (this.props.spotify_authorized && this.props.uri){ - this.props.spotifyActions.following(this.props.uri) - } + super(props); } remove(){ - this.props.spotifyActions.following(this.props.uri, 'DELETE') + this.props.spotifyActions.following(this.props.uri, 'DELETE'); } add(){ - this.props.spotifyActions.following(this.props.uri, 'PUT') + this.props.spotifyActions.following(this.props.uri, 'PUT'); } render(){ if (!this.props.uri){ - return false + return false; } - var className = '' + var className = ''; // Inherit passed-down classes if (this.props.className){ - className += ' '+this.props.className + className += ' '+this.props.className; } // Loader if (helpers.isLoading(this.props.load_queue,['/following','/followers','me/albums/contains/?ids=','me/albums/?ids='])){ - className += ' working' + className += ' working'; } if (!this.props.spotify_authorized){ diff --git a/src/js/views/Album.js b/src/js/views/Album.js index da564e6c..1ada9e4c 100755 --- a/src/js/views/Album.js +++ b/src/js/views/Album.js @@ -61,14 +61,15 @@ class Album extends React.Component{ } loadAlbum(props = this.props){ - switch(helpers.uriSource(props.params.uri )){ + switch(helpers.uriSource(props.params.uri)){ case 'spotify': if (props.album && props.album.tracks && props.album.artists_uris){ console.info('Loading album from index') } else { - this.props.spotifyActions.getAlbum(props.params.uri ); + this.props.spotifyActions.getAlbum(props.params.uri); } + this.props.spotifyActions.following(props.params.uri); break; default: diff --git a/src/js/views/Artist.js b/src/js/views/Artist.js index 3d54828d..066cdec6 100755 --- a/src/js/views/Artist.js +++ b/src/js/views/Artist.js @@ -35,10 +35,10 @@ class Artist extends React.Component{ componentWillReceiveProps(nextProps){ if (nextProps.params.uri != this.props.params.uri){ - this.loadArtist(nextProps ) + this.loadArtist(nextProps); }else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ if (helpers.uriSource(this.props.params.uri ) != 'spotify'){ - this.loadArtist(nextProps ) + this.loadArtist(nextProps); } } } @@ -50,7 +50,7 @@ class Artist extends React.Component{ items: [this.props.artist], uris: [this.props.params.uri] } - this.props.uiActions.showContextMenu(data) + this.props.uiActions.showContextMenu(data); } loadArtist(props = this.props){ @@ -58,16 +58,17 @@ class Artist extends React.Component{ case 'spotify': if (props.artist && props.artist.albums_uris && props.artist.related_artists_uris){ - console.info('Loading spotify artist from index') + console.info('Loading spotify artist from index'); } else { this.props.spotifyActions.getArtist(props.params.uri, true); } + this.props.spotifyActions.following(props.params.uri); break default: if (props.mopidy_connected){ if (props.artist && props.artist.images){ - console.info('Loading local artist from index') + console.info('Loading local artist from index'); } else { this.props.mopidyActions.getArtist(props.params.uri); } diff --git a/src/js/views/Playlist.js b/src/js/views/Playlist.js index cdaced14..647375db 100755 --- a/src/js/views/Playlist.js +++ b/src/js/views/Playlist.js @@ -60,12 +60,13 @@ class Playlist extends React.Component{ switch (helpers.uriSource(props.params.uri)){ case 'spotify': - this.props.spotifyActions.getPlaylist(props.params.uri ) + this.props.spotifyActions.getPlaylist(props.params.uri); + this.props.spotifyActions.following(props.params.uri); break default: if (props.mopidy_connected){ - this.props.mopidyActions.getPlaylist(props.params.uri ) + this.props.mopidyActions.getPlaylist(props.params.uri); } break } diff --git a/src/js/views/Track.js b/src/js/views/Track.js index 2a3734a0..bf5e26e6 100755 --- a/src/js/views/Track.js +++ b/src/js/views/Track.js @@ -46,7 +46,7 @@ class Track 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 ) != 'spotify'){ - this.loadTrack(nextProps ) + this.loadTrack(nextProps); } } @@ -73,7 +73,8 @@ class Track extends React.Component{ if (props.track){ console.info('Loading track from index'); } else { - this.props.spotifyActions.getTrack(props.params.uri ); + this.props.spotifyActions.getTrack(props.params.uri); + this.props.spotifyActions.following(props.params.uri); } break; diff --git a/src/js/views/User.js b/src/js/views/User.js index d78f95a0..4eb26842 100755 --- a/src/js/views/User.js +++ b/src/js/views/User.js @@ -27,23 +27,24 @@ class User extends React.Component{ componentWillReceiveProps(nextProps){ if (nextProps.params.uri != this.props.params.uri){ - this.loadUser(nextProps ) + this.loadUser(nextProps); } } loadUser(props = this.props){ if (!props.user){ - this.props.spotifyActions.getUser(props.params.uri) + this.props.spotifyActions.getUser(props.params.uri); + this.props.spotifyActions.following(props.params.uri); } // We got a user, but we haven't fetched their playlists yet if (props.user && !props.user.playlists_uris){ - this.props.spotifyActions.getUserPlaylists(props.params.uri) + this.props.spotifyActions.getUserPlaylists(props.params.uri); } } loadMore(){ - this.props.spotifyActions.getURL(this.props.user.playlists_more, 'SPOTIFY_USER_PLAYLISTS_LOADED', this.props.params.uri ) + this.props.spotifyActions.getURL(this.props.user.playlists_more, 'SPOTIFY_USER_PLAYLISTS_LOADED', this.props.params.uri); } isMe(){ @@ -61,9 +62,11 @@ class User extends React.Component{ ) } - if (!this.props.user) return null + if (!this.props.user){ + return null; + } - var playlists = [] + 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]