Files
Iris/src/js/views/modals/AddToPlaylist.js

108 lines
3.9 KiB
JavaScript
Raw Normal View History

2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
import React from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import ReactGA from 'react-ga';
2018-07-21 15:43:01 +12:00
import Loader from '../../components/Loader';
2018-07-21 15:43:01 +12:00
import Modal from './Modal';
import Icon from '../../components/Icon';
import Thumbnail from '../../components/Thumbnail';
2019-09-05 15:36:11 +12:00
import * as coreActions from '../../services/core/actions';
import * as uiActions from '../../services/ui/actions';
import * as mopidyActions from '../../services/mopidy/actions';
import * as spotifyActions from '../../services/spotify/actions';
2018-07-21 15:43:01 +12:00
import * as helpers from '../../helpers';
class AddToPlaylist extends React.Component {
2019-09-05 15:36:11 +12:00
constructor(props) {
super(props);
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
if (!this.props.spotify_library_playlists) {
this.props.spotifyActions.getLibraryPlaylists();
}
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
if (!this.props.mopidy_library_playlists && this.props.mopidy_connected) {
this.props.mopidyActions.getLibraryPlaylists();
}
}
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
playlistSelected(playlist_uri) {
this.props.coreActions.addTracksToPlaylist(playlist_uri, this.props.uris);
window.history.back();
}
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
render() {
if (!this.props.playlists) return <div className="empty">No editable playlists</div>;
let playlists = [];
for (const uri in this.props.playlists) {
if (this.props.playlists[uri].can_edit) playlists.push(this.props.playlists[uri]);
}
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
playlists = helpers.sortItems(playlists, 'name');
2018-07-21 15:43:01 +12:00
const isLoading = this.props.spotify_library_playlists_status == 'running';
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
return (
<Modal className="modal--add-to-playlist">
<h1>Add to playlist</h1>
<h2 className="mid_grey-text">
Select playlist to add
{this.props.uris.length}
{' '}
track
{this.props.uris.length > 1 ? 's' : null}
{' '}
to
2019-09-05 15:36:11 +12:00
</h2>
{playlists.length <= 0 ? <div className="no-results">No playlists available</div> : null}
<div className="list small playlists">
{
playlists.map((playlist) => (
<div className="list__item" key={playlist.uri} onClick={() => this.playlistSelected(playlist.uri)}>
<Thumbnail images={playlist.images} size="small" />
<h4 className="list__item__name">{ playlist.name }</h4>
<ul className="list__item__details details">
<li><Icon type="fontawesome" className="source" name={helpers.sourceIcon(playlist.uri)} /></li>
<li>
{ playlist.tracks_total ? (
<span className="mid_grey-text">
{ playlist.tracks_total }
{' '}
tracks
</span>
) : null }
2019-09-05 15:36:11 +12:00
</li>
</ul>
</div>
))
2018-07-21 15:43:01 +12:00
}
2019-09-05 15:36:11 +12:00
</div>
{isLoading && <Loader body lazy loading />}
2019-09-05 15:36:11 +12:00
</Modal>
);
}
2018-07-21 15:43:01 +12:00
}
2019-09-05 15:36:11 +12:00
const mapStateToProps = (state, ownProps) => ({
uris: (ownProps.match.params.uris ? decodeURIComponent(ownProps.match.params.uris).split(',') : []),
mopidy_connected: state.mopidy.connected,
mopidy_uri_schemes: state.mopidy.uri_schemes,
mopidy_library_playlists: state.mopidy.library_playlists,
mopidy_library_playlists_status: (state.ui.processes.MOPIDY_LIBRARY_PLAYLISTS_PROCESSOR !== undefined ? state.ui.processes.MOPIDY_LIBRARY_PLAYLISTS_PROCESSOR.status : null),
spotify_library_playlists: state.spotify.library_playlists,
spotify_library_playlists_status: (state.ui.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR !== undefined ? state.ui.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR.status : null),
load_queue: state.ui.load_queue,
me_id: (state.spotify.me ? state.spotify.me.id : false),
playlists: state.core.playlists,
});
2018-07-21 15:43:01 +12:00
2019-09-05 15:36:11 +12:00
const mapDispatchToProps = (dispatch) => ({
coreActions: bindActionCreators(coreActions, dispatch),
uiActions: bindActionCreators(uiActions, dispatch),
mopidyActions: bindActionCreators(mopidyActions, dispatch),
spotifyActions: bindActionCreators(spotifyActions, dispatch),
});
2018-07-21 15:43:01 +12:00
export default connect(mapStateToProps, mapDispatchToProps)(AddToPlaylist);