2016-10-27 10:02:12 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2017-05-30 09:06:59 +12:00
|
|
|
import { Link } from 'react-router'
|
2016-10-27 10:02:12 +13:00
|
|
|
|
|
|
|
|
import Header from '../../components/Header'
|
|
|
|
|
import AlbumGrid from '../../components/AlbumGrid'
|
2017-05-30 09:06:59 +12:00
|
|
|
import Parallax from '../../components/Parallax'
|
|
|
|
|
import Thumbnail from '../../components/Thumbnail'
|
|
|
|
|
import ArtistSentence from '../../components/ArtistSentence'
|
2016-11-01 08:57:28 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2017-05-30 09:06:59 +12:00
|
|
|
|
2017-05-22 04:19:44 +12:00
|
|
|
import * as helpers from '../../helpers'
|
2016-11-01 08:57:28 +13:00
|
|
|
import * as uiActions from '../../services/ui/actions'
|
2017-05-30 09:08:40 +12:00
|
|
|
import * as mopidyActions from '../../services/mopidy/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
|
|
|
}
|
|
|
|
|
|
2017-05-30 09:06:59 +12:00
|
|
|
playAlbum(e,album){
|
|
|
|
|
this.props.mopidyActions.playURIs([album.uri],album.uri)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderIntro(album = null){
|
|
|
|
|
if (album){
|
|
|
|
|
return (
|
|
|
|
|
<div className="intro">
|
|
|
|
|
<Parallax image={helpers.sizedImages(album.images).huge} blur />
|
|
|
|
|
<div className="content cf">
|
|
|
|
|
<Link to={global.baseURL+'album/'+album.uri}>
|
|
|
|
|
<Thumbnail images={album.images} />
|
|
|
|
|
</Link>
|
|
|
|
|
<Link to={global.baseURL+'album/'+album.uri}>
|
|
|
|
|
<h1>{album.name}</h1>
|
|
|
|
|
</Link>
|
|
|
|
|
<h3>
|
|
|
|
|
<ArtistSentence artists={album.artists} />
|
|
|
|
|
</h3>
|
|
|
|
|
<div className="actions">
|
|
|
|
|
<button className="primary" onClick={e => this.playAlbum(e,album)}>Play</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
} else {
|
|
|
|
|
return (
|
|
|
|
|
<div className="intro">
|
|
|
|
|
<Parallax />
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 10:02:12 +13:00
|
|
|
render(){
|
2017-05-22 04:19:44 +12:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_browse/new-releases'])){
|
|
|
|
|
return (
|
|
|
|
|
<div className="view discover-new-releases-view">
|
|
|
|
|
<Header icon="leaf" title="New Releases" />
|
|
|
|
|
<div className="body-loader">
|
|
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
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])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-30 09:06:59 +12:00
|
|
|
// Pull the first playlist out and we'll use this as a banner
|
|
|
|
|
var first_album = albums.splice(0,1)
|
|
|
|
|
if (first_album){
|
|
|
|
|
first_album = first_album[0]
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 10:02:12 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view discover-new-releases-view">
|
2017-05-30 09:06:59 +12:00
|
|
|
<Header className="overlay" icon="leaf" title="New Releases" />
|
|
|
|
|
{this.renderIntro(first_album)}
|
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 {
|
2017-05-22 04:19:44 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-01-15 11:40:08 +13:00
|
|
|
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),
|
2017-05-30 09:08:40 +12:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2016-10-27 10:02:12 +13:00
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(DiscoverNewReleases)
|