Categories using index now too

This commit is contained in:
James Barnsley
2017-01-19 11:47:15 +13:00
parent 97ada1ed15
commit b12881057c
8 changed files with 240 additions and 146 deletions

View File

@ -14,17 +14,26 @@ class DiscoverCategories extends React.Component{
super(props);
}
// on render
componentDidMount(){
this.props.spotifyActions.getCategories();
}
render(){
if (!this.props.categories) return null
// convert categories object into simple array
var categories = []
for (var key in this.props.categories){
if (this.props.categories.hasOwnProperty(key)){
categories.push(this.props.categories[key])
}
}
return (
<div className="view discover-categories-view">
<Header icon="grid" title="Genre / Mood" />
<section className="grid-wrapper">
{ this.props.spotify.categories ? <CategoryGrid categories={this.props.spotify.categories.items} /> : null }
<CategoryGrid categories={categories} />
</section>
</div>
);
@ -39,7 +48,9 @@ class DiscoverCategories extends React.Component{
**/
const mapStateToProps = (state, ownProps) => {
return state;
return {
categories: state.ui.categories
}
}
const mapDispatchToProps = (dispatch) => {

View File

@ -26,18 +26,21 @@ class DiscoverCategory extends React.Component{
}
loadMore(){
if( !this.props.playlists_next || !this.props.playlists_next ) return
this.props.spotifyActions.getURL( this.props.playlists_next, 'SPOTIFY_NEW_RELEASES_LOADED_MORE' );
if (this.props.category.playlists_more){
this.props.spotifyActions.getURL( this.props.category.playlists_more, 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED', 'category:'+this.props.params.id );
}
}
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])
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])
}
}
}
@ -63,7 +66,7 @@ class DiscoverCategory extends React.Component{
const mapStateToProps = (state, ownProps) => {
return {
playlists: state.ui.playlists,
category: state.spotify.category
category: (state.ui.categories && typeof(state.ui.categories['category:'+ownProps.params.id]) !== 'undefined' ? state.ui.categories['category:'+ownProps.params.id] : false )
}
}