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 lastfmActions from '../services/lastfm/actions'
|
|
|
|
|
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-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 )
|
|
|
|
|
}else if( !this.props.mopidy.connected && nextProps.mopidy.connected ){
|
|
|
|
|
if( helpers.uriSource( this.props.params.uri ) == 'local' ){
|
|
|
|
|
this.loadAlbum( nextProps )
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
loadAlbum( props = this.props ){
|
|
|
|
|
var source = helpers.uriSource( props.params.uri );
|
2016-11-07 21:21:15 +13:00
|
|
|
|
2016-11-01 13:19:51 +13:00
|
|
|
if( source == 'spotify' ){
|
|
|
|
|
this.props.spotifyActions.getAlbum( props.params.uri );
|
2016-11-07 21:21:15 +13:00
|
|
|
|
2016-11-01 13:19:51 +13:00
|
|
|
}else if( source == 'local' && props.mopidy.connected ){
|
|
|
|
|
this.props.mopidyActions.getAlbum( props.params.uri );
|
2016-10-03 14:44:27 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-07 21:21:15 +13:00
|
|
|
loadMore(){
|
|
|
|
|
if( !this.props.spotify.album || !this.props.spotify.album.tracks.next ) return
|
|
|
|
|
this.props.spotifyActions.getURL( this.props.spotify.album.tracks.next, 'SPOTIFY_ALBUM_LOADED_MORE' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
album(){
|
|
|
|
|
var album = {
|
|
|
|
|
name: false,
|
|
|
|
|
tracks: {
|
|
|
|
|
items: []
|
|
|
|
|
},
|
|
|
|
|
artists: [],
|
|
|
|
|
images: []
|
2016-11-02 16:51:00 +13:00
|
|
|
}
|
2016-11-07 21:21:15 +13:00
|
|
|
|
|
|
|
|
switch( helpers.uriSource( this.props.params.uri ) ){
|
|
|
|
|
|
|
|
|
|
case 'spotify':
|
|
|
|
|
Object.assign(album, this.props.spotify.album)
|
|
|
|
|
album.artists = this.props.spotify.artists
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'local':
|
|
|
|
|
Object.assign(album, this.props.mopidy.album)
|
|
|
|
|
if( this.props.lastfm.album.image ) album.images = this.props.lastfm.album.image
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return album
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
var album = this.album()
|
2016-11-01 13:19:51 +13:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view album-view">
|
|
|
|
|
<div className="intro">
|
2016-11-07 21:21:15 +13:00
|
|
|
<Thumbnail size="large" images={ album.images } />
|
|
|
|
|
<ArtistGrid artists={ album.artists } />
|
2016-11-02 16:51:00 +13:00
|
|
|
<ul className="details">
|
2016-11-02 21:23:35 +13:00
|
|
|
<li>{ album.tracks.total } tracks, <Dater type="total-time" data={album.tracks.items} /></li>
|
2016-11-02 16:51:00 +13:00
|
|
|
{ album.release_date ? <li>Released <Dater type="date" data={ 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">
|
|
|
|
|
<h1>{ album.name }</h1>
|
|
|
|
|
<h3><ArtistSentence artists={ album.artists } /></h3>
|
2016-10-31 09:25:15 +13:00
|
|
|
</div>
|
2016-11-07 21:21:15 +13:00
|
|
|
|
|
|
|
|
<section className="list-wrapper">
|
|
|
|
|
<TrackList tracks={ album.tracks.items } />
|
|
|
|
|
<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 state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2016-10-19 14:09:34 +13:00
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
2016-11-07 21:21:15 +13:00
|
|
|
lastfmActions: bindActionCreators(lastfmActions, 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)
|