Files
Iris/src/js/views/Album.js

127 lines
3.8 KiB
JavaScript
Raw Normal View History

2016-10-03 14:44:27 +13:00
import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import FontAwesome from 'react-fontawesome'
2016-11-01 13:19:51 +13:00
let helpers = require('../helpers.js')
2016-10-03 14:44:27 +13:00
import TrackList from '../components/TrackList'
2016-10-31 09:25:15 +13:00
import Thumbnail from '../components/Thumbnail'
import Parallax from '../components/Parallax'
import ArtistSentence from '../components/ArtistSentence'
2016-10-31 16:49:42 +13:00
import ArtistGrid from '../components/ArtistGrid'
2016-11-18 13:21:30 +13:00
import FollowButton from '../components/FollowButton'
2016-10-31 16:49:42 +13:00
import Dater from '../components/Dater'
2016-11-07 21:21:15 +13:00
import LazyLoadListener from '../components/LazyLoadListener'
2016-10-19 14:09:34 +13:00
import * as mopidyActions from '../services/mopidy/actions'
2016-11-07 21:21:15 +13:00
import * as spotifyActions from '../services/spotify/actions'
2016-10-03 14:44:27 +13:00
class Album extends React.Component{
constructor(props) {
super(props);
}
componentDidMount(){
2016-11-01 13:19:51 +13:00
this.loadAlbum();
2016-10-03 14:44:27 +13:00
}
componentWillReceiveProps( nextProps ){
// if our URI has changed, fetch new album
if( nextProps.params.uri != this.props.params.uri ){
2016-11-01 13:19:51 +13:00
this.loadAlbum( nextProps )
// if mopidy has just connected AND we're a local album, go get
}else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){
2016-11-01 13:19:51 +13:00
if( helpers.uriSource( this.props.params.uri ) == 'local' ){
this.loadAlbum( nextProps )
}
}
}
loadAlbum( props = this.props ){
switch( helpers.uriSource( props.params.uri ) ){
2016-11-07 21:21:15 +13:00
case 'spotify':
this.props.spotifyActions.getAlbum( props.params.uri );
break;
2016-11-07 21:21:15 +13:00
case 'local':
if( props.mopidy_connected ) this.props.mopidyActions.getAlbum( props.params.uri );
break;
2016-10-03 14:44:27 +13:00
}
}
2016-11-07 21:21:15 +13:00
loadMore(){
2016-11-09 20:34:37 +13:00
if( !this.props.album.tracks_more ) return
this.props.spotifyActions.getURL( this.props.album.tracks_more, 'SPOTIFY_ALBUM_LOADED_MORE' );
2016-11-07 21:21:15 +13:00
}
play(){
var tracks_uris = helpers.asURIs( this.props.album.tracks )
this.props.mopidyActions.playURIs( tracks_uris )
}
2016-11-07 21:21:15 +13:00
render(){
if( !this.props.album ) return null
2016-11-01 13:19:51 +13:00
return (
<div className="view album-view">
<div className="intro">
2016-11-09 20:34:37 +13:00
<Thumbnail size="large" images={ this.props.album.images } />
<ArtistGrid artists={ this.props.album.artists } />
<div className="actions">
<button className="large primary" onClick={ e => this.play() }>Play</button>
2016-11-18 13:21:30 +13:00
<FollowButton uri={this.props.params.uri} addText="Add to library" removeText="Remove from library" />
</div>
<ul className="details">
2016-11-09 20:34:37 +13:00
<li>{ this.props.album.tracks_total } tracks, <Dater type="total-time" data={this.props.album.tracks} /></li>
{ this.props.album.release_date ? <li>Released <Dater type="date" data={ this.props.album.release_date } /></li> : null }
2016-11-07 21:21:15 +13:00
<li><FontAwesome name={helpers.sourceIcon( this.props.params.uri )} /> {helpers.uriSource( this.props.params.uri )} playlist</li>
</ul>
2016-11-01 13:19:51 +13:00
</div>
<div className="main">
2016-11-07 21:21:15 +13:00
2016-11-01 13:19:51 +13:00
<div className="title">
<h1>{ this.props.album.name }</h1>
<h3><ArtistSentence artists={ this.props.album.artists } /></h3>
2016-10-31 09:25:15 +13:00
</div>
2016-11-07 21:21:15 +13:00
<section className="list-wrapper">
2016-11-09 20:34:37 +13:00
{ this.props.album.tracks ? <TrackList tracks={ this.props.album.tracks } /> : null }
2016-11-07 21:21:15 +13:00
<LazyLoadListener loadMore={ () => this.loadMore() }/>
</section>
2016-10-03 14:44:27 +13:00
</div>
2016-11-01 13:19:51 +13:00
</div>
);
2016-10-03 14:44:27 +13:00
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
album: state.ui.album,
spotify_authorized: state.spotify.authorized,
mopidy_connected: state.mopidy.connected
};
2016-10-03 14:44:27 +13:00
}
const mapDispatchToProps = (dispatch) => {
return {
2016-10-19 14:09:34 +13:00
mopidyActions: bindActionCreators(mopidyActions, dispatch),
2016-10-16 13:28:21 +13:00
spotifyActions: bindActionCreators(spotifyActions, dispatch)
2016-10-03 14:44:27 +13:00
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Album)