Playlists loaded by App now for future global use

This commit is contained in:
James Barnsley
2016-11-10 13:44:14 +13:00
parent a1bb8bf7d4
commit 47377b5c78
2 changed files with 27 additions and 20 deletions

View File

@ -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
}

View File

@ -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)
export default connect(mapStateToProps)(LibraryPlaylists)