2016-10-20 21:38:01 +13:00
|
|
|
|
2019-09-05 15:36:11 +12:00
|
|
|
import React from 'react';
|
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
|
import { bindActionCreators } from 'redux';
|
2019-09-10 06:59:44 +12:00
|
|
|
import Loader from '../../components/Loader';
|
2019-09-05 15:36:11 +12:00
|
|
|
import TrackList from '../../components/TrackList';
|
|
|
|
|
import Header from '../../components/Header';
|
|
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener';
|
|
|
|
|
import Icon from '../../components/Icon';
|
|
|
|
|
import * as uiActions from '../../services/ui/actions';
|
|
|
|
|
import * as mopidyActions from '../../services/mopidy/actions';
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions';
|
2020-03-03 16:39:37 +13:00
|
|
|
import { isLoading } from '../../util/helpers';
|
2020-07-19 20:41:14 +12:00
|
|
|
import { I18n, i18n } from '../../locale';
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
class LibraryTracks extends React.Component {
|
2019-09-05 15:36:11 +12:00
|
|
|
componentDidMount() {
|
2020-07-19 20:41:14 +12:00
|
|
|
this.props.uiActions.setWindowTitle(i18n('library.tracks.title'));
|
2019-09-05 15:36:11 +12:00
|
|
|
|
2020-05-12 20:32:48 +12:00
|
|
|
if (!this.props.spotify_available) {
|
2020-07-19 20:41:14 +12:00
|
|
|
this.props.uiActions.createNotification({
|
|
|
|
|
level: 'warning',
|
|
|
|
|
content: i18n('errors.enable_first', { provider: i18n('services.spotify.title') }),
|
|
|
|
|
});
|
2019-09-05 15:36:11 +12:00
|
|
|
} else 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',
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
playAll() {
|
|
|
|
|
this.props.spotifyActions.getLibraryTracksAndPlay();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
render() {
|
2019-09-05 15:36:11 +12:00
|
|
|
// Note trailing "?" makes sure our context menu in_library checks doesn't interfere
|
2020-03-03 16:39:37 +13:00
|
|
|
if (isLoading(this.props.load_queue, ['spotify_me/tracks?'])) {
|
2019-09-05 15:36:11 +12:00
|
|
|
return (
|
|
|
|
|
<div className="view library-tracks-view">
|
2020-07-19 20:41:14 +12:00
|
|
|
<Header icon="music" title={i18n('library.tracks.title')} />
|
2019-09-10 06:59:44 +12:00
|
|
|
<Loader body loading />
|
2019-09-05 15:36:11 +12:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tracks = [];
|
|
|
|
|
if (this.props.library_tracks && this.props.tracks) {
|
|
|
|
|
for (let i = 0; i < this.props.library_tracks.length; i++) {
|
|
|
|
|
const uri = this.props.library_tracks[i];
|
|
|
|
|
if (this.props.tracks.hasOwnProperty(uri)) {
|
|
|
|
|
tracks.push(this.props.tracks[uri]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const options = (
|
|
|
|
|
<a className="button button--no-hover" onClick={(e) => this.playAll(e)}>
|
2019-09-10 06:59:44 +12:00
|
|
|
<Icon name="play_circle_filled" />
|
2020-07-19 20:41:14 +12:00
|
|
|
<I18n path="actions.play_all" />
|
2019-09-05 15:36:11 +12:00
|
|
|
</a>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="view library-tracks-view">
|
|
|
|
|
<Header options={options} uiActions={this.props.uiActions}>
|
|
|
|
|
<Icon name="music_note" type="material" />
|
2020-07-19 20:41:14 +12:00
|
|
|
<I18n path="library.tracks.title" />
|
2019-09-05 15:36:11 +12:00
|
|
|
</Header>
|
|
|
|
|
<section className="content-wrapper">
|
|
|
|
|
<TrackList tracks={tracks} />
|
|
|
|
|
<LazyLoadListener
|
|
|
|
|
loadKey={this.props.library_tracks_more}
|
|
|
|
|
showLoader={this.props.library_tracks_more}
|
2019-09-10 06:59:44 +12:00
|
|
|
loadMore={() => this.loadMore()}
|
2019-09-05 15:36:11 +12:00
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2016-10-20 21:38:01 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
2019-09-05 15:36:11 +12:00
|
|
|
* */
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => ({
|
|
|
|
|
load_queue: state.ui.load_queue,
|
|
|
|
|
tracks: state.core.tracks,
|
2020-05-12 20:32:48 +12:00
|
|
|
spotify_available: state.spotify.access_token,
|
2019-09-05 15:36:11 +12:00
|
|
|
library_tracks: state.spotify.library_tracks,
|
|
|
|
|
library_tracks_more: state.spotify.library_tracks_more,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch),
|
|
|
|
|
});
|
|
|
|
|
|
2019-09-10 06:59:44 +12:00
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryTracks);
|