diff --git a/src/js/views/App.js b/src/js/views/App.js index f7f3dde5..269274cc 100755 --- a/src/js/views/App.js +++ b/src/js/views/App.js @@ -26,12 +26,33 @@ class App extends React.Component{ } componentWillMount(){ + window.addEventListener("keyup", this.handleKeyUp, false); + window.addEventListener("keydown", this.handleKeyDown, false); + } + + componentDidMount(){ this.props.pusherActions.connect(); this.props.mopidyActions.connect(); this.props.spotifyActions.connect(); + this.props.spotifyActions.getAllLibraryPlaylists(); + } - window.addEventListener("keyup", this.handleKeyUp, false); - window.addEventListener("keydown", this.handleKeyDown, false); + componentWillReceiveProps(nextProps){ + + // mopidy comes online + if( !this.props.mopidy_connected && nextProps.mopidy_connected ){ + this.props.mopidyActions.getPlaylists(); + } + + // spotify authorized + if( !this.props.spotify_authorized && nextProps.spotify_authorized ){ + this.props.spotifyActions.getAllLibraryPlaylists(); + } + + // spotify un-authorized + if( this.props.spotify_authorized && !nextProps.spotify_authorized ){ + // TODO: flush out playlists and then re-fetch mopidy + } } componentWillUnmount(){ @@ -92,6 +113,8 @@ class App extends React.Component{ const mapStateToProps = (state, ownProps) => { return { + mopidy_connected: state.mopidy.connected, + spotify_authorized: state.spotify.authorized, play_state: state.mopidy.play_state, context_menu: state.ui.context_menu } diff --git a/src/js/views/library/LibraryPlaylists.js b/src/js/views/library/LibraryPlaylists.js index 013b06fb..8b4a8c93 100755 --- a/src/js/views/library/LibraryPlaylists.js +++ b/src/js/views/library/LibraryPlaylists.js @@ -16,12 +16,6 @@ class LibraryPlaylists extends React.Component{ super(props); } - // on render - componentDidMount(){ - if( this.props.mopidy_connected ) this.props.mopidyActions.getPlaylists(); - if( this.props.spotify_authorized ) this.props.spotifyActions.getAllLibraryPlaylists(); - } - render(){ if( !this.props.playlists ) return null var columns = [ @@ -52,18 +46,8 @@ class LibraryPlaylists extends React.Component{ const mapStateToProps = (state, ownProps) => { return { - playlists: state.ui.playlists, - playlists_more: state.ui.playlists_more, - mopidy_connected: state.mopidy.connected, - spotify_authorized: state.spotify.authorized + playlists: state.ui.playlists } } -const mapDispatchToProps = (dispatch) => { - return { - mopidyActions: bindActionCreators(mopidyActions, dispatch), - spotifyActions: bindActionCreators(spotifyActions, dispatch) - } -} - -export default connect(mapStateToProps, mapDispatchToProps)(LibraryPlaylists) \ No newline at end of file +export default connect(mapStateToProps)(LibraryPlaylists) \ No newline at end of file