Files
Iris/src/js/views/discover/DiscoverCategory.js

76 lines
1.9 KiB
JavaScript
Raw Normal View History

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(){
if( !this.props.playlists_next || !this.props.playlists_next ) return
this.props.spotifyActions.getURL( this.props.playlists_next, 'SPOTIFY_NEW_RELEASES_LOADED_MORE' );
2016-11-01 08:57:28 +13:00
}
2016-10-26 16:55:47 +13:00
render(){
if (!this.props.category) return null
var playlists = []
for (var i = 0; i < this.props.category.playlists.length; i++){
var uri = this.props.category.playlists[i]
if (this.props.playlists.hasOwnProperty(uri)){
playlists.push(this.props.playlists[uri])
}
}
2016-10-26 16:55:47 +13:00
return (
<div className="view discover-categories-view">
<Header icon="grid" title={this.props.category.name} />
<section className="grid-wrapper">
<PlaylistGrid playlists={playlists} />
</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) => {
return {
playlists: state.ui.playlists,
category: state.spotify.category
}
2016-10-26 16:55:47 +13:00
}
const mapDispatchToProps = (dispatch) => {
return {
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverCategory)