2016-10-26 16:55:47 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
|
|
|
|
import Header from '../../components/Header'
|
|
|
|
|
import PlaylistGrid from '../../components/PlaylistGrid'
|
2016-11-01 08:57:28 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2016-10-26 16:55:47 +13:00
|
|
|
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class DiscoverCategory extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
|
|
|
|
this.props.spotifyActions.getCategory( this.props.params.id );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps( nextProps ){
|
|
|
|
|
if( nextProps.params.id != this.props.params.id ){
|
|
|
|
|
this.props.spotifyActions.getCategory( nextProps.params.id );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
loadMore(){
|
2017-01-19 11:47:15 +13:00
|
|
|
if (this.props.category.playlists_more){
|
|
|
|
|
this.props.spotifyActions.getURL( this.props.category.playlists_more, 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED', 'category:'+this.props.params.id );
|
|
|
|
|
}
|
2016-11-01 08:57:28 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-26 16:55:47 +13:00
|
|
|
render(){
|
2017-01-14 01:01:48 +13:00
|
|
|
if (!this.props.category) return null
|
|
|
|
|
|
|
|
|
|
var playlists = []
|
2017-01-19 11:47:15 +13:00
|
|
|
if (this.props.category.playlists_uris){
|
|
|
|
|
for (var i = 0; i < this.props.category.playlists_uris.length; i++){
|
|
|
|
|
var key = this.props.category.playlists_uris[i]
|
|
|
|
|
if (this.props.playlists.hasOwnProperty(key)){
|
|
|
|
|
playlists.push(this.props.playlists[key])
|
|
|
|
|
}
|
2017-01-14 01:01:48 +13:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-26 16:55:47 +13:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view discover-categories-view">
|
2017-01-14 01:01:48 +13:00
|
|
|
<Header icon="grid" title={this.props.category.name} />
|
2016-11-04 09:35:39 +13:00
|
|
|
<section className="grid-wrapper">
|
2017-01-14 01:01:48 +13:00
|
|
|
<PlaylistGrid playlists={playlists} />
|
2016-11-04 09:35:39 +13:00
|
|
|
</section>
|
2016-11-01 08:57:28 +13:00
|
|
|
<LazyLoadListener loadMore={ () => this.loadMore() }/>
|
2016-10-26 16:55:47 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2017-01-14 01:01:48 +13:00
|
|
|
return {
|
|
|
|
|
playlists: state.ui.playlists,
|
2017-01-19 11:47:15 +13:00
|
|
|
category: (state.ui.categories && typeof(state.ui.categories['category:'+ownProps.params.id]) !== 'undefined' ? state.ui.categories['category:'+ownProps.params.id] : false )
|
2017-01-14 01:01:48 +13:00
|
|
|
}
|
2016-10-26 16:55:47 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverCategory)
|