Files
Iris/src/js/views/Playlist.js

103 lines
3.0 KiB
JavaScript
Raw Normal View History

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')
import TrackList from '../components/TrackList'
2016-10-31 16:49:42 +13:00
import Thumbnail from '../components/Thumbnail'
import Dater from '../components/Dater'
import LazyLoadListener from '../components/LazyLoadListener'
import * as spotifyActions from '../services/spotify/actions'
import * as mopidyActions from '../services/mopidy/actions'
class Playlist extends React.Component{
constructor(props) {
super(props);
}
componentDidMount(){
2016-11-01 11:49:04 +13:00
this.loadPlaylist();
}
componentWillReceiveProps( nextProps ){
if( nextProps.params.uri != this.props.params.uri ){
2016-11-01 11:49:04 +13:00
this.loadPlaylist( nextProps )
2016-11-09 21:13:40 +13:00
}else if( !this.props.mopidy_connected && nextProps.mopidy_connected ){
2016-11-01 11:49:04 +13:00
if( helpers.uriSource( this.props.params.uri ) == 'm3u' ){
this.loadPlaylist( nextProps )
}
}
}
2016-11-01 11:49:04 +13:00
loadPlaylist( props = this.props ){
var source = helpers.uriSource( props.params.uri );
if( source == 'spotify' ){
this.props.spotifyActions.getPlaylist( props.params.uri );
2016-11-09 21:13:40 +13:00
}else if( source == 'm3u' && props.mopidy_connected ){
2016-11-01 11:49:04 +13:00
this.props.mopidyActions.getPlaylist( props.params.uri );
}
}
loadMore(){
2016-11-09 21:13:40 +13:00
if( !this.props.playlist.tracks_more ) return
this.props.spotifyActions.getURL( this.props.playlist.tracks_more, 'SPOTIFY_PLAYLIST_LOADED_MORE' );
}
2016-11-01 13:19:51 +13:00
render(){
2016-11-09 21:13:40 +13:00
if( !this.props.playlist ) return null;
var scheme = helpers.uriSource( this.props.params.uri );
2016-11-01 13:19:51 +13:00
return (
<div className="view playlist-view">
<div className="intro">
2016-11-09 21:13:40 +13:00
<Thumbnail size="large" images={ this.props.playlist.images } />
<ul className="details">
2016-11-09 21:13:40 +13:00
<li>{ this.props.playlist.tracks_total } tracks, <Dater type="total-time" data={this.props.playlist.tracks} /></li>
{ this.props.playlist.last_modified ? <li>Updated <Dater type="ago" data={this.props.playlist.last_modified} /> ago</li> : null }
{ scheme == 'spotify' ? <li><FontAwesome name="spotify" /> Spotify playlist</li> : null }
{ scheme == 'm3u' ? <li><FontAwesome name="folder" /> Local playlist</li> : null }
</ul>
</div>
2016-11-01 13:19:51 +13:00
<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 21:13:40 +13:00
<h1>{ this.props.playlist.name }</h1>
2016-11-01 11:49:04 +13:00
</div>
2016-11-07 21:21:15 +13:00
<section className="list-wrapper">
2016-11-09 21:13:40 +13:00
<TrackList tracks={ this.props.playlist.tracks } />
2016-11-07 21:21:15 +13:00
<LazyLoadListener loadMore={ () => this.loadMore() }/>
</section>
2016-11-01 11:49:04 +13:00
</div>
2016-11-01 13:19:51 +13:00
</div>
)
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
2016-11-09 21:13:40 +13:00
return {
playlist: state.ui.playlist,
mopidy_connected: state.mopidy.connected
}
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Playlist)