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

164 lines
4.2 KiB
JavaScript
Raw Normal View History

2016-10-27 10:02:12 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
2016-10-27 10:02:12 +13:00
import Header from '../../components/Header'
2018-05-15 21:30:57 +12:00
import Icon from '../../components/Icon'
2016-10-27 10:02:12 +13:00
import AlbumGrid from '../../components/AlbumGrid'
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-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{
2017-10-10 13:05:28 +13:00
constructor(props){
2016-10-27 10:02:12 +13:00
super(props);
}
componentDidMount(){
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(){
this.props.spotifyActions.getMore(
this.props.new_releases_more,
null,
{
type: 'SPOTIFY_NEW_RELEASES_LOADED',
key: null
}
);
2016-11-01 08:57:28 +13:00
}
playAlbum(e,album){
this.props.mopidyActions.playURIs([album.uri],album.uri)
}
2017-05-31 08:40:55 +12:00
handleContextMenu(e,item){
e.preventDefault()
var data = {
e: e,
context: 'album',
uris: [item.uri],
items: [item]
}
this.props.uiActions.showContextMenu(data)
}
renderIntro(album = null){
if (album){
return (
<div className="intro">
<Parallax image={helpers.sizedImages(album.images).huge} blur />
<div className="content cf">
2017-05-31 08:40:55 +12:00
<Link
to={global.baseURL+'album/'+album.uri}
onContextMenu={e => this.handleContextMenu(e,album)}>
<Thumbnail images={album.images} />
</Link>
2017-09-19 16:57:59 +12:00
<h2>
<Link to={global.baseURL+'album/'+album.uri}>
{album.name}
</Link>
</h2>
<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">
2018-05-15 21:30:57 +12:00
<Header>
<Icon name="new_releases" type="material" />
New releases
</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>
)
}
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])
}
}
}
// 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">
2018-05-15 21:30:57 +12:00
<Header className="overlay">
<Icon name="new_releases" type="material" />
New releases
</Header>
{this.renderIntro(first_album)}
2017-06-18 05:47:36 +12:00
<section className="content-wrapper grid-wrapper">
<AlbumGrid albums={albums} />
</section>
<LazyLoadListener loading={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) => {
return {
2017-05-22 04:19:44 +12:00
load_queue: state.ui.load_queue,
albums: state.core.albums,
2017-08-02 21:11:22 +12:00
new_releases: state.core.new_releases,
new_releases_more: state.core.new_releases_more,
new_releases_total: state.core.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)