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

104 lines
2.8 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'
2017-05-22 04:19:44 +12:00
import * as helpers from '../../helpers'
2016-10-26 16:55:47 +13:00
import * as spotifyActions from '../../services/spotify/actions'
class DiscoverCategory extends React.Component{
2017-10-10 13:05:28 +13:00
constructor(props){
2016-10-26 16:55:47 +13:00
super(props);
}
componentDidMount(){
2017-01-19 13:19:11 +13:00
this.loadCategory()
2016-10-26 16:55:47 +13:00
}
2017-10-10 13:05:28 +13:00
componentWillReceiveProps(nextProps){
if (nextProps.params.id != this.props.params.id){
2017-01-19 13:19:11 +13:00
this.loadCategory()
2016-10-26 16:55:47 +13:00
}
}
2017-01-19 13:19:11 +13:00
loadCategory(){
2017-10-10 13:05:28 +13:00
if (!this.props.category || !this.props.category.playlists_uris) this.props.spotifyActions.getCategory(this.props.params.id );
2017-01-19 13:19:11 +13:00
}
2016-11-01 08:57:28 +13:00
loadMore(){
this.props.spotifyActions.loadMore(
this.props.category.playlists_more,
null,
{
type: 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED',
key: 'category:'+this.props.params.id
}
);
2016-11-01 08:57:28 +13:00
}
2016-10-26 16:55:47 +13:00
render(){
2017-05-22 04:19:44 +12:00
if (helpers.isLoading(this.props.load_queue,['spotify_browse/categories/'])){
return (
<div className="view discover-categories-view">
<Header icon="grid" title={(this.props.category ? this.props.category.name : 'Category')} />
2017-08-07 21:34:33 +12:00
<div className="body-loader loading">
2017-05-22 04:19:44 +12:00
<div className="loader"></div>
</div>
</div>
)
}
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])
}
}
}
2016-10-26 16:55:47 +13:00
return (
<div className="view discover-categories-view">
<Header icon="grid" title={this.props.category.name} />
2017-06-18 05:47:36 +12:00
<div className="content-wrapper">
<section className="grid-wrapper">
<PlaylistGrid playlists={playlists} />
</section>
<LazyLoadListener loading={this.props.category.playlists_more} loadMore={ () => this.loadMore() }/>
2017-06-18 05:47:36 +12:00
</div>
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 {
2017-05-22 04:19:44 +12:00
load_queue: state.ui.load_queue,
playlists: state.core.playlists,
2017-08-02 21:11:22 +12:00
category: (state.core.categories && state.core.categories['category:'+ownProps.params.id] !== undefined ? state.core.categories['category:'+ownProps.params.id] : false )
}
2016-10-26 16:55:47 +13:00
}
const mapDispatchToProps = (dispatch) => {
return {
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverCategory)