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

122 lines
3.3 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'
2018-05-15 21:30:57 +12:00
import Icon from '../../components/Icon'
2016-10-26 16:55:47 +13:00
import PlaylistGrid from '../../components/PlaylistGrid'
2016-11-01 08:57:28 +13:00
import LazyLoadListener from '../../components/LazyLoadListener'
2018-05-15 21:30:57 +12:00
2017-05-22 04:19:44 +12:00
import * as helpers from '../../helpers'
import * as uiActions from '../../services/ui/actions'
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(){
this.loadCategory();
this.setWindowTitle();
2016-10-26 16:55:47 +13:00
}
2017-10-10 13:05:28 +13:00
componentWillReceiveProps(nextProps){
if (nextProps.match.params.id != this.props.match.params.id){
this.loadCategory();
}
if (!this.props.category && nextProps.category){
this.setWindowTitle(nextProps.category);
}
}
setWindowTitle(category = this.props.category){
if (category){
this.props.uiActions.setWindowTitle(category.name);
} else{
this.props.uiActions.setWindowTitle("Genre / Mood");
2016-10-26 16:55:47 +13:00
}
}
2017-01-19 13:19:11 +13:00
loadCategory(){
if (!this.props.category){
this.props.spotifyActions.getCategory(this.props.match.params.id);
}
if (!this.props.category.playlists_uris){
this.props.spotifyActions.getCategoryPlaylists(this.props.match.params.id);
}
2017-01-19 13:19:11 +13:00
}
2016-11-01 08:57:28 +13:00
loadMore(){
this.props.spotifyActions.getMore(
this.props.category.playlists_more,
null,
{
type: 'SPOTIFY_CATEGORY_PLAYLISTS_LOADED_MORE',
uri: 'category:'+this.props.match.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">
2018-05-15 21:30:57 +12:00
<Header>
<Icon name="mood" type="material" />
{(this.props.category ? this.props.category.name : 'Category')}
</Header>
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;
2017-05-22 04:19:44 +12:00
}
var category = helpers.collate(this.props.category, {playlists: this.props.playlists});
2016-10-26 16:55:47 +13:00
return (
<div className="view discover-categories-view">
<Header uiActions={this.props.uiActions}>
2018-05-15 21:30:57 +12:00
<Icon name="mood" type="material" />
{category.name}
2018-05-15 21:30:57 +12:00
</Header>
2017-06-18 05:47:36 +12:00
<div className="content-wrapper">
<section className="grid-wrapper">
<PlaylistGrid playlists={category.playlists} />
2017-06-18 05:47:36 +12:00
</section>
2018-09-03 08:24:49 +12:00
<LazyLoadListener
loadKey={category.playlists_more}
showLoader={category.playlists_more}
2018-09-03 08:24:49 +12:00
loadMore={() => this.loadMore()}
/>
2017-06-18 05:47:36 +12:00
</div>
2016-10-26 16:55:47 +13:00
</div>
);
}
}
const mapStateToProps = (state, ownProps) => {
return {
2017-05-22 04:19:44 +12:00
load_queue: state.ui.load_queue,
playlists: state.core.playlists,
category: (state.spotify.categories && state.spotify.categories['category:'+ownProps.match.params.id] !== undefined ? state.spotify.categories['category:'+ownProps.match.params.id] : false )
}
2016-10-26 16:55:47 +13:00
}
const mapDispatchToProps = (dispatch) => {
return {
uiActions: bindActionCreators(uiActions, dispatch),
2016-10-26 16:55:47 +13:00
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverCategory)