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

89 lines
2.3 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 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-10-16 13:28:21 +13:00
import * as spotifyActions from '../services/spotify/actions'
2016-10-19 14:09:34 +13:00
import * as mopidyActions from '../services/mopidy/actions'
2016-10-03 14:44:27 +13:00
class Album extends React.Component{
constructor(props) {
super(props);
}
// on render
componentDidMount(){
this.props.spotifyActions.getAlbum( this.props.params.uri );
2016-10-03 14:44:27 +13:00
}
// when props changed
componentWillReceiveProps( nextProps ){
if( nextProps.params.uri != this.props.params.uri ){
this.props.spotifyActions.getAlbum( nextProps.params.uri );
2016-10-03 14:44:27 +13:00
}
}
2016-10-31 16:49:42 +13:00
totalTime(){
if( !this.props.spotify.album ) return null
var tracks = this.props.spotify.tracks.items;
var duration = 0;
for( var i = 0; i < tracks.length; i++ ){
duration += tracks[i].duration_ms;
}
return duration;
}
2016-10-17 14:27:48 +13:00
render(){
2016-10-16 13:28:21 +13:00
if( this.props.spotify.album ){
2016-10-31 16:49:42 +13:00
var album = this.props.spotify.album;
2016-10-03 14:44:27 +13:00
return (
2016-10-26 16:55:47 +13:00
<div className="view album-view">
2016-10-31 09:25:15 +13:00
<div className="intro">
2016-10-31 16:49:42 +13:00
<Thumbnail size="large" images={ album.images } />
<ArtistGrid artists={ album.artists } />
<div className="details">
<div>{ album.tracks.total } tracks, { this.totalTime }</div>
<div>Released <Dater type="date" data={ album.release_date } /></div>
</div>
2016-10-31 09:25:15 +13:00
</div>
<div className="main">
2016-10-31 16:49:42 +13:00
<div className="title">
<h1>{ album.name }</h1>
<h3><ArtistSentence artists={ album.artists } /></h3>
</div>
<TrackList tracks={ album.tracks.items } />
2016-10-31 09:25:15 +13:00
</div>
2016-10-03 14:44:27 +13:00
</div>
);
}
return null;
}
}
/**
* 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-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)