Files
Iris/src/js/views/library/LibraryTracks.js

95 lines
2.4 KiB
JavaScript
Raw Normal View History

import React, { PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router'
import TrackList from '../../components/TrackList'
import Header from '../../components/Header'
import LazyLoadListener from '../../components/LazyLoadListener'
2017-05-22 04:19:44 +12:00
import * as helpers from '../../helpers'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryTracks extends React.Component{
2017-10-10 13:05:28 +13:00
constructor(props){
super(props);
}
// on render
componentDidMount(){
if (this.props.library_tracks === undefined){
this.props.spotifyActions.getLibraryTracks();
}
}
loadMore(){
this.props.spotifyActions.getMore(
this.props.library_tracks_more,
null,
{
type: 'SPOTIFY_LIBRARY_TRACKS_LOADED_MORE'
}
);
}
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>
)
}
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">
<TrackList tracks={tracks} />
<LazyLoadListener loading={this.props.library_tracks_more} loadMore={() => this.loadMore()}/>
</section>
2016-10-26 16:55:47 +13:00
</div>
);
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
2017-05-22 04:19:44 +12:00
load_queue: state.ui.load_queue,
tracks: state.core.tracks,
library_tracks: state.spotify.library_tracks,
library_tracks_more: state.spotify.library_tracks_more
}
}
const mapDispatchToProps = (dispatch) => {
return {
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(LibraryTracks)