2016-10-27 10:02:12 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
|
|
|
|
|
import Header from '../../components/Header'
|
|
|
|
|
import AlbumGrid from '../../components/AlbumGrid'
|
2016-11-01 08:57:28 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2016-10-27 10:02:12 +13:00
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
import * as uiActions from '../../services/ui/actions'
|
2016-10-27 10:02:12 +13:00
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
|
|
|
|
|
|
|
|
|
class DiscoverNewReleases extends React.Component{
|
|
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentDidMount(){
|
2017-01-15 11:40:08 +13:00
|
|
|
if (!this.props.new_releases) this.props.spotifyActions.getNewReleases();
|
2016-10-27 10:02:12 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-01 08:57:28 +13:00
|
|
|
loadMore(){
|
2017-01-15 11:40:08 +13:00
|
|
|
this.props.spotifyActions.getURL(this.props.new_releases_more, 'SPOTIFY_NEW_RELEASES_LOADED');
|
2016-11-01 08:57:28 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-27 10:02:12 +13:00
|
|
|
render(){
|
2017-01-15 11:40:08 +13:00
|
|
|
|
|
|
|
|
var albums = []
|
|
|
|
|
if (this.props.new_releases){
|
|
|
|
|
for (var i = 0; i < this.props.new_releases.length; i++){
|
|
|
|
|
var uri = this.props.new_releases[i]
|
|
|
|
|
if (this.props.albums.hasOwnProperty(uri)){
|
|
|
|
|
albums.push(this.props.albums[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 10:02:12 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view discover-new-releases-view">
|
|
|
|
|
<Header icon="leaf" title="New Releases" />
|
2016-11-04 09:35:39 +13:00
|
|
|
<section className="grid-wrapper">
|
2017-01-15 11:40:08 +13:00
|
|
|
<AlbumGrid albums={albums} />
|
2016-11-04 09:35:39 +13:00
|
|
|
</section>
|
2017-01-27 08:15:59 +13:00
|
|
|
<LazyLoadListener enabled={this.props.new_releases_more} loadMore={ () => this.loadMore() }/>
|
2016-10-27 10:02:12 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2017-01-15 11:40:08 +13:00
|
|
|
return {
|
|
|
|
|
albums: state.ui.albums,
|
|
|
|
|
new_releases: state.ui.new_releases,
|
|
|
|
|
new_releases_more: state.ui.new_releases_more,
|
|
|
|
|
new_releases_total: state.ui.new_releases_total
|
|
|
|
|
}
|
2016-10-27 10:02:12 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-11-01 08:57:28 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
2016-10-27 10:02:12 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverNewReleases)
|