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-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'
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-11-24 08:11:41 +13:00
import SidebarToggleButton from '../components/SidebarToggleButton'
2016-10-23 23:48:06 +13:00
2016-11-19 13:06:08 +13:00
import * as helpers from '../helpers'
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 )
}
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" >
2016-11-24 08:11:41 +13:00
< SidebarToggleButton / >
2016-11-01 13:19:51 +13:00
< 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 < / b u t t o n >
2016-11-19 13:06:08 +13:00
{ helpers . uriSource ( this . props . params . uri ) == 'spotify' ? < FollowButton uri = { this . props . params . uri } addText = "Add to library" removeText = "Remove from library" / > : null }
2016-11-18 08:29:13 +13:00
< / d i v >
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 } / > < / l i >
2016-11-09 13:18:03 +13:00
{ this . props . album . release _date ? < li > Released < Dater type = "date" data = { this . props . album . release _date } / > < / l i > : n u l l }
2016-11-07 21:21:15 +13:00
< li > < FontAwesome name = { helpers . sourceIcon ( this . props . params . uri ) } / > { helpers . uriSource ( this . props . params . uri ) } playlist < / l i >
2016-11-02 16:51:00 +13:00
< / u l >
2016-11-01 13:19:51 +13:00
< / d i v >
< 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 } < / h 1 >
< h3 > < ArtistSentence artists = { this . props . album . artists } / > < / h 3 >
2016-10-31 09:25:15 +13:00
< / d i v >
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 ( ) } / >
< / s e c t i o n >
2016-10-03 14:44:27 +13:00
< / d i v >
2016-11-01 13:19:51 +13:00
< / d i v >
) ;
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 )