2016-10-03 14:44:27 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-11-02 16:51:00 +13:00
|
|
|
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
|
|
|
|
2016-10-17 10:39:11 +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'
|
|
|
|
|
import Dater from '../components/Dater'
|
2016-11-07 21:21:15 +13:00
|
|
|
import LazyLoadListener from '../components/LazyLoadListener'
|
2016-10-23 23:48:06 +13:00
|
|
|
|
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 ){
|
2016-11-09 13:18:03 +13:00
|
|
|
|
|
|
|
|
// if our URI has changed, fetch new album
|
2016-10-16 12:37:37 +13:00
|
|
|
if( nextProps.params.uri != this.props.params.uri ){
|
2016-11-01 13:19:51 +13:00
|
|
|
this.loadAlbum( nextProps )
|
2016-11-09 13:18:03 +13:00
|
|
|
|
|
|
|
|
// 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 ){
|
2016-11-09 13:18:03 +13:00
|
|
|
switch( helpers.uriSource( props.params.uri ) ){
|
2016-11-07 21:21:15 +13:00
|
|
|
|
2016-11-09 13:18:03 +13:00
|
|
|
case 'spotify':
|
|
|
|
|
this.props.spotifyActions.getAlbum( props.params.uri );
|
|
|
|
|
break;
|
2016-11-07 21:21:15 +13:00
|
|
|
|
2016-11-09 13:18:03 +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
|
|
|
}
|
|
|
|
|
|
2016-11-18 08:29:13 +13:00
|
|
|
play(){
|
|
|
|
|
var tracks_uris = helpers.asURIs( this.props.album.tracks )
|
|
|
|
|
this.props.mopidyActions.playURIs( tracks_uris )
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
follow(){
|
2016-11-18 10:02:05 +13:00
|
|
|
this.props.spotifyActions.toggleAlbumInLibrary( this.props.params.uri, 'PUT' )
|
2016-11-18 08:29:13 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: Once unfollowing occurs, remove playlist from global playlists list
|
|
|
|
|
unfollow(){
|
2016-11-18 10:02:05 +13:00
|
|
|
this.props.spotifyActions.toggleAlbumInLibrary( this.props.params.uri, 'DELETE' )
|
2016-11-18 08:29:13 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
renderExtraButtons(){
|
|
|
|
|
switch( helpers.uriSource( this.props.params.uri ) ){
|
|
|
|
|
case 'spotify':
|
|
|
|
|
if( !this.props.spotify_authorized ) return null
|
2016-11-18 10:02:05 +13:00
|
|
|
if( this.props.album.following ){
|
|
|
|
|
return <button className="large tertiary" onClick={ e => this.unfollow() }>Remove from library</button>
|
2016-11-18 08:29:13 +13:00
|
|
|
}
|
2016-11-18 10:02:05 +13:00
|
|
|
return <button className="large tertiary" onClick={ e => this.follow() }>Add to library</button>
|
2016-11-18 08:29:13 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 21:21:15 +13:00
|
|
|
render(){
|
2016-11-09 13:18:03 +13:00
|
|
|
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 } />
|
2016-11-09 13:18:03 +13:00
|
|
|
<ArtistGrid artists={ this.props.album.artists } />
|
2016-11-18 08:29:13 +13:00
|
|
|
|
|
|
|
|
<div className="actions">
|
|
|
|
|
<button className="large primary" onClick={ e => this.play() }>Play</button>
|
|
|
|
|
{ this.renderExtraButtons() }
|
|
|
|
|
</div>
|
|
|
|
|
|
2016-11-02 16:51:00 +13:00
|
|
|
<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>
|
2016-11-09 13:18:03 +13:00
|
|
|
{ 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>
|
2016-11-02 16:51:00 +13:00
|
|
|
</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">
|
2016-11-09 13:18:03 +13:00
|
|
|
<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) => {
|
2016-11-09 13:18:03 +13:00
|
|
|
return {
|
|
|
|
|
album: state.ui.album,
|
2016-11-18 10:02:05 +13:00
|
|
|
spotify_authorized: state.spotify.authorized,
|
2016-11-09 13:18:03 +13:00
|
|
|
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)
|