Moving follow check to asset, rather than component, fixes #146

This commit is contained in:
James Barnsley
2017-11-01 08:14:26 +13:00
parent 7f8a9c26dc
commit 5b0a0b27b8
6 changed files with 31 additions and 30 deletions

View File

@ -12,38 +12,32 @@ import * as spotifyActions from '../services/spotify/actions'
class FollowButton extends React.Component{ class FollowButton extends React.Component{
constructor(props){ constructor(props){
super(props) super(props);
}
componentDidMount(){
if (this.props.spotify_authorized && this.props.uri){
this.props.spotifyActions.following(this.props.uri)
}
} }
remove(){ remove(){
this.props.spotifyActions.following(this.props.uri, 'DELETE') this.props.spotifyActions.following(this.props.uri, 'DELETE');
} }
add(){ add(){
this.props.spotifyActions.following(this.props.uri, 'PUT') this.props.spotifyActions.following(this.props.uri, 'PUT');
} }
render(){ render(){
if (!this.props.uri){ if (!this.props.uri){
return false return false;
} }
var className = '' var className = '';
// Inherit passed-down classes // Inherit passed-down classes
if (this.props.className){ if (this.props.className){
className += ' '+this.props.className className += ' '+this.props.className;
} }
// Loader // Loader
if (helpers.isLoading(this.props.load_queue,['/following','/followers','me/albums/contains/?ids=','me/albums/?ids='])){ 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){ if (!this.props.spotify_authorized){

View File

@ -61,14 +61,15 @@ class Album extends React.Component{
} }
loadAlbum(props = this.props){ loadAlbum(props = this.props){
switch(helpers.uriSource(props.params.uri )){ switch(helpers.uriSource(props.params.uri)){
case 'spotify': case 'spotify':
if (props.album && props.album.tracks && props.album.artists_uris){ if (props.album && props.album.tracks && props.album.artists_uris){
console.info('Loading album from index') console.info('Loading album from index')
} else { } else {
this.props.spotifyActions.getAlbum(props.params.uri ); this.props.spotifyActions.getAlbum(props.params.uri);
} }
this.props.spotifyActions.following(props.params.uri);
break; break;
default: default:

View File

@ -35,10 +35,10 @@ class Artist extends React.Component{
componentWillReceiveProps(nextProps){ componentWillReceiveProps(nextProps){
if (nextProps.params.uri != this.props.params.uri){ if (nextProps.params.uri != this.props.params.uri){
this.loadArtist(nextProps ) this.loadArtist(nextProps);
}else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ }else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
if (helpers.uriSource(this.props.params.uri ) != 'spotify'){ 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], items: [this.props.artist],
uris: [this.props.params.uri] uris: [this.props.params.uri]
} }
this.props.uiActions.showContextMenu(data) this.props.uiActions.showContextMenu(data);
} }
loadArtist(props = this.props){ loadArtist(props = this.props){
@ -58,16 +58,17 @@ class Artist extends React.Component{
case 'spotify': case 'spotify':
if (props.artist && props.artist.albums_uris && props.artist.related_artists_uris){ 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 { } else {
this.props.spotifyActions.getArtist(props.params.uri, true); this.props.spotifyActions.getArtist(props.params.uri, true);
} }
this.props.spotifyActions.following(props.params.uri);
break break
default: default:
if (props.mopidy_connected){ if (props.mopidy_connected){
if (props.artist && props.artist.images){ if (props.artist && props.artist.images){
console.info('Loading local artist from index') console.info('Loading local artist from index');
} else { } else {
this.props.mopidyActions.getArtist(props.params.uri); this.props.mopidyActions.getArtist(props.params.uri);
} }

View File

@ -60,12 +60,13 @@ class Playlist extends React.Component{
switch (helpers.uriSource(props.params.uri)){ switch (helpers.uriSource(props.params.uri)){
case 'spotify': case 'spotify':
this.props.spotifyActions.getPlaylist(props.params.uri ) this.props.spotifyActions.getPlaylist(props.params.uri);
this.props.spotifyActions.following(props.params.uri);
break break
default: default:
if (props.mopidy_connected){ if (props.mopidy_connected){
this.props.mopidyActions.getPlaylist(props.params.uri ) this.props.mopidyActions.getPlaylist(props.params.uri);
} }
break break
} }

View File

@ -46,7 +46,7 @@ class Track extends React.Component{
// if mopidy has just connected AND we're a local album, go get // if mopidy has just connected AND we're a local album, go get
} else if (!this.props.mopidy_connected && nextProps.mopidy_connected){ } else if (!this.props.mopidy_connected && nextProps.mopidy_connected){
if (helpers.uriSource(this.props.params.uri ) != 'spotify'){ 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){ if (props.track){
console.info('Loading track from index'); console.info('Loading track from index');
} else { } else {
this.props.spotifyActions.getTrack(props.params.uri ); this.props.spotifyActions.getTrack(props.params.uri);
this.props.spotifyActions.following(props.params.uri);
} }
break; break;

View File

@ -27,23 +27,24 @@ class User extends React.Component{
componentWillReceiveProps(nextProps){ componentWillReceiveProps(nextProps){
if (nextProps.params.uri != this.props.params.uri){ if (nextProps.params.uri != this.props.params.uri){
this.loadUser(nextProps ) this.loadUser(nextProps);
} }
} }
loadUser(props = this.props){ loadUser(props = this.props){
if (!props.user){ 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 // We got a user, but we haven't fetched their playlists yet
if (props.user && !props.user.playlists_uris){ if (props.user && !props.user.playlists_uris){
this.props.spotifyActions.getUserPlaylists(props.params.uri) this.props.spotifyActions.getUserPlaylists(props.params.uri);
} }
} }
loadMore(){ 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(){ 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){ if (this.props.user.playlists_uris){
for (var i = 0; i < this.props.user.playlists_uris.length; i++){ for (var i = 0; i < this.props.user.playlists_uris.length; i++){
var uri = this.props.user.playlists_uris[i] var uri = this.props.user.playlists_uris[i]