import React, { PropTypes } from 'react' import { connect } from 'react-redux' import { bindActionCreators } from 'redux' import FontAwesome from 'react-fontawesome' let helpers = require('../helpers.js') import TrackList from '../components/TrackList' import Thumbnail from '../components/Thumbnail' import Dater from '../components/Dater' import * as spotifyActions from '../services/spotify/actions' import * as mopidyActions from '../services/mopidy/actions' class Playlist extends React.Component{ constructor(props) { super(props); } componentDidMount(){ this.loadPlaylist(); } componentWillReceiveProps( nextProps ){ if( nextProps.params.uri != this.props.params.uri ){ this.loadPlaylist( nextProps ) }else if( !this.props.mopidy.connected && nextProps.mopidy.connected ){ if( helpers.uriSource( this.props.params.uri ) == 'm3u' ){ this.loadPlaylist( nextProps ) } } } loadPlaylist( props = this.props ){ var source = helpers.uriSource( props.params.uri ); if( source == 'spotify' ){ this.props.spotifyActions.getPlaylist( props.params.uri ); }else if( source == 'm3u' && props.mopidy.connected ){ this.props.mopidyActions.getPlaylist( props.params.uri ); } } render(){ var source = helpers.uriSource( this.props.params.uri ); if( source == 'spotify' ) var playlist = this.props.spotify.playlist if( source == 'm3u' ) var playlist = this.props.mopidy.playlist if( !playlist ) return null; return (
{ playlist.images ? : null }
  • { playlist.tracks.total } tracks,
  • { playlist.last_modified ?
  • Updated ago
  • : null } { source == 'spotify' ?
  • Spotify playlist
  • : null } { source == 'm3u' ?
  • Local playlist
  • : null }

{ playlist.name }

) } } /** * Export our component * * We also integrate our global store, using connect() **/ const mapStateToProps = (state, ownProps) => { return state; } const mapDispatchToProps = (dispatch) => { return { mopidyActions: bindActionCreators(mopidyActions, dispatch), spotifyActions: bindActionCreators(spotifyActions, dispatch) } } export default connect(mapStateToProps, mapDispatchToProps)(Playlist)