2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
|
import { Link } from 'react-router'
|
|
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
import TrackList from '../../components/TrackList'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../../components/Header'
|
2016-11-19 11:13:01 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2016-10-20 21:38:01 +13:00
|
|
|
|
2017-05-22 04:19:44 +12:00
|
|
|
import * as helpers from '../../helpers'
|
2016-10-21 09:56:07 +13:00
|
|
|
import * as mopidyActions from '../../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
2016-10-20 21:38:01 +13:00
|
|
|
|
|
|
|
|
class LibraryTracks extends React.Component{
|
|
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2016-10-20 21:38:01 +13:00
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// on render
|
|
|
|
|
componentDidMount(){
|
2017-11-12 09:05:34 +13:00
|
|
|
if (this.props.library_tracks === undefined){
|
|
|
|
|
this.props.spotifyActions.getLibraryTracks();
|
|
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-19 11:13:01 +13:00
|
|
|
loadMore(){
|
2017-11-12 09:05:34 +13:00
|
|
|
this.props.spotifyActions.getMore(
|
|
|
|
|
this.props.library_tracks_more,
|
|
|
|
|
null,
|
|
|
|
|
{
|
|
|
|
|
type: 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE'
|
|
|
|
|
}
|
|
|
|
|
);
|
2016-11-19 11:13:01 +13:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 21:38:01 +13:00
|
|
|
render(){
|
2017-05-22 04:19:44 +12:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_me/tracks'])){
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-tracks-view">
|
|
|
|
|
<Header icon="music" title="My tracks" />
|
2017-08-07 21:34:33 +12:00
|
|
|
<div className="body-loader loading">
|
2017-05-22 04:19:44 +12:00
|
|
|
<div className="loader"></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-12 09:05:34 +13:00
|
|
|
var tracks = [];
|
|
|
|
|
if (this.props.library_tracks && this.props.tracks){
|
|
|
|
|
for (var i = 0; i < this.props.library_tracks.length; i++){
|
|
|
|
|
var uri = this.props.library_tracks[i]
|
|
|
|
|
if (this.props.tracks.hasOwnProperty(uri)){
|
|
|
|
|
tracks.push(this.props.tracks[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-26 16:55:47 +13:00
|
|
|
return (
|
|
|
|
|
<div className="view library-tracks-view">
|
|
|
|
|
<Header icon="music" title="My tracks" />
|
2017-06-18 05:47:36 +12:00
|
|
|
<section className="content-wrapper">
|
2017-11-12 09:05:34 +13:00
|
|
|
<TrackList tracks={tracks} />
|
|
|
|
|
<LazyLoadListener loading={this.props.library_tracks_more} loadMore={() => this.loadMore()}/>
|
2016-11-04 09:35:39 +13:00
|
|
|
</section>
|
2016-10-26 16:55:47 +13:00
|
|
|
</div>
|
|
|
|
|
);
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2016-11-19 13:06:08 +13:00
|
|
|
return {
|
2017-05-22 04:19:44 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-11-12 09:05:34 +13:00
|
|
|
tracks: state.core.tracks,
|
|
|
|
|
library_tracks: state.spotify.library_tracks,
|
|
|
|
|
library_tracks_more: state.spotify.library_tracks_more
|
2016-11-19 13:06:08 +13:00
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryTracks)
|