Files
Iris/src/js/components/Modal/AddToPlaylistModal.js

71 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-11-14 17:32:36 +13:00
2018-02-01 08:06:40 +13:00
import React, { PropTypes } from 'react';
import FontAwesome from 'react-fontawesome';
2018-02-01 08:06:40 +13:00
import Icon from '../Icon';
import Thumbnail from '../Thumbnail';
import * as helpers from '../../helpers';
2016-11-14 17:32:36 +13:00
export default class AddToPlaylistModal extends React.Component{
2016-11-14 17:32:36 +13:00
constructor(props){
super(props)
if (!this.props.spotify_library_playlists){
this.props.spotifyActions.getLibraryPlaylists()
}
if (!this.props.mopidy_library_playlists){
this.props.mopidyActions.getLibraryPlaylists()
}
2016-11-14 17:32:36 +13:00
}
2017-10-10 13:05:28 +13:00
playlistSelected(playlist_uri){
this.props.coreActions.addTracksToPlaylist(playlist_uri, this.props.tracks_uris )
2016-11-14 17:32:36 +13:00
this.props.uiActions.closeModal()
}
render(){
2017-10-10 13:05:28 +13:00
if (!this.props.playlists ) return <div className="empty">No editable playlists</div>
2016-11-14 17:32:36 +13:00
var playlists = []
2017-01-16 21:49:04 +13:00
for (var uri in this.props.playlists){
2017-10-10 13:05:28 +13:00
if (this.props.playlists[uri].can_edit ) playlists.push(this.props.playlists[uri] )
2016-11-14 17:32:36 +13:00
}
2017-01-16 21:49:04 +13:00
playlists = helpers.sortItems(playlists, 'name')
2017-08-22 08:38:03 +12:00
var loader = null
if (this.props.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR && this.props.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR.status == 'running'){
loader = (
<div className='lazy-loader body-loader loading'>
<div className="loader"></div>
</div>
)
}
2016-11-14 17:32:36 +13:00
return (
2016-11-21 07:59:52 +13:00
<div>
2017-06-21 09:16:26 +12:00
<h1>Add to playlist</h1>
<h2 className="grey-text">Select playlist to add {this.props.tracks_uris.length} track{this.props.tracks_uris.length>1?'s':null} to</h2>
{playlists.length <= 0 ? <div className="no-results">No playlists available</div> : null}
<div className="list small playlists">
2016-11-21 07:59:52 +13:00
{
2017-10-10 13:05:28 +13:00
playlists.map(playlist => {
2016-11-21 07:59:52 +13:00
return (
<div className="list-item" key={playlist.uri} onClick={ () => this.playlistSelected(playlist.uri) }>
<Thumbnail images={playlist.images} size="small" />
<h3 className="name">{ playlist.name }</h3>
<ul className="details">
<li><FontAwesome className="source" name={helpers.sourceIcon(playlist.uri)} /></li>
<li>{ playlist.tracks_total ? <span className="grey-text">&nbsp;{ playlist.tracks_total } tracks</span> : null }</li>
</ul>
2016-11-21 07:59:52 +13:00
</div>
)
})
}
</div>
2017-08-22 08:38:03 +12:00
{loader}
2016-11-14 17:32:36 +13:00
</div>
)
}
}