2016-10-17 10:39:11 +13:00
|
|
|
|
|
|
|
|
import React, { PropTypes } from 'react'
|
|
|
|
|
import { connect } from 'react-redux'
|
|
|
|
|
import { bindActionCreators } from 'redux'
|
2016-10-17 14:27:48 +13:00
|
|
|
import { Link } from 'react-router'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-11-12 16:36:36 +13:00
|
|
|
import PlaylistGrid from '../../components/PlaylistGrid'
|
2016-11-21 16:26:47 +13:00
|
|
|
import List from '../../components/List'
|
2018-04-19 13:34:16 +12:00
|
|
|
import DropdownField from '../../components/Fields/DropdownField'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../../components/Header'
|
2018-04-19 13:34:16 +12:00
|
|
|
import FilterField from '../../components/Fields/FilterField'
|
2017-10-20 14:58:19 +13:00
|
|
|
import LazyLoadListener from '../../components/LazyLoadListener'
|
2018-05-15 21:30:57 +12:00
|
|
|
import Icon from '../../components/Icon'
|
2016-10-21 23:27:50 +13:00
|
|
|
|
2016-12-09 18:47:10 +13:00
|
|
|
import * as helpers from '../../helpers'
|
2017-08-11 21:59:14 +12:00
|
|
|
import * as coreActions from '../../services/core/actions'
|
2016-11-14 11:20:02 +13:00
|
|
|
import * as uiActions from '../../services/ui/actions'
|
2016-10-21 09:56:07 +13:00
|
|
|
import * as mopidyActions from '../../services/mopidy/actions'
|
|
|
|
|
import * as spotifyActions from '../../services/spotify/actions'
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2016-10-21 09:56:07 +13:00
|
|
|
class LibraryPlaylists extends React.Component{
|
2016-10-17 10:39:11 +13:00
|
|
|
|
2017-10-10 13:05:28 +13:00
|
|
|
constructor(props){
|
2017-08-14 20:02:41 +12:00
|
|
|
super(props)
|
|
|
|
|
|
|
|
|
|
this.state = {
|
2017-10-20 14:58:19 +13:00
|
|
|
filter: '',
|
|
|
|
|
limit: 50,
|
|
|
|
|
per_page: 50
|
2017-08-14 20:02:41 +12:00
|
|
|
}
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
|
2017-08-11 08:08:03 +12:00
|
|
|
componentDidMount(){
|
2018-06-29 14:26:06 +12:00
|
|
|
this.props.uiActions.setWindowTitle("Playlists");
|
|
|
|
|
|
2017-08-14 20:02:41 +12:00
|
|
|
if (!this.props.mopidy_library_playlists && this.props.mopidy_connected && (this.props.source == 'all' || this.props.source == 'local')){
|
2017-08-12 23:01:55 +12:00
|
|
|
this.props.mopidyActions.getLibraryPlaylists()
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-05 20:59:11 +12:00
|
|
|
if (this.props.spotify_enabled && this.props.spotify_library_playlists_status !== 'finished' && (this.props.source == 'all' || this.props.source == 'spotify')){
|
2017-08-12 23:01:55 +12:00
|
|
|
this.props.spotifyActions.getLibraryPlaylists()
|
2017-08-11 08:08:03 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
componentWillReceiveProps(newProps){
|
2018-04-19 13:34:16 +12:00
|
|
|
|
2017-08-14 20:02:41 +12:00
|
|
|
if (newProps.mopidy_connected && (newProps.source == 'all' || newProps.source == 'local')){
|
2017-08-12 23:01:55 +12:00
|
|
|
|
|
|
|
|
// We've just connected
|
|
|
|
|
if (!this.props.mopidy_connected){
|
2018-04-19 13:34:16 +12:00
|
|
|
this.props.mopidyActions.getLibraryPlaylists();
|
2017-08-12 23:01:55 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Filter changed, but we haven't got this provider's library yet
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.props.source != 'all' && this.props.source != 'local' && !newProps.mopidy_library_playlists){
|
2017-08-12 23:01:55 +12:00
|
|
|
this.props.mopidyActions.getLibraryPlaylists()
|
|
|
|
|
}
|
2017-08-11 08:08:03 +12:00
|
|
|
}
|
|
|
|
|
|
2018-08-05 20:59:11 +12:00
|
|
|
if (newProps.spotify_enabled && (newProps.source == 'all' || newProps.source == 'spotify')){
|
2017-08-12 23:01:55 +12:00
|
|
|
|
|
|
|
|
// Filter changed, but we haven't got this provider's library yet
|
2018-06-26 08:51:11 +12:00
|
|
|
if (newProps.spotify_library_playlists_status != 'finished' && newProps.spotify_library_playlists_status != 'started'){
|
2017-08-12 23:01:55 +12:00
|
|
|
this.props.spotifyActions.getLibraryPlaylists()
|
|
|
|
|
}
|
2017-08-11 08:08:03 +12:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-02 09:06:15 +13:00
|
|
|
handleContextMenu(e,item){
|
|
|
|
|
var data = {
|
|
|
|
|
e: e,
|
|
|
|
|
context: 'playlist',
|
|
|
|
|
uris: [item.uri],
|
2017-03-12 16:19:06 +13:00
|
|
|
items: [item]
|
2017-02-02 09:06:15 +13:00
|
|
|
}
|
|
|
|
|
this.props.uiActions.showContextMenu(data)
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 09:07:47 +13:00
|
|
|
setSort(value){
|
|
|
|
|
var reverse = false
|
2017-10-10 13:05:28 +13:00
|
|
|
if (this.props.sort == value ) reverse = !this.props.sort_reverse
|
2016-12-12 09:07:47 +13:00
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
|
library_playlists_sort_reverse: reverse,
|
|
|
|
|
library_playlists_sort: value
|
|
|
|
|
}
|
|
|
|
|
this.props.uiActions.set(data)
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 16:26:47 +13:00
|
|
|
renderView(){
|
2017-10-20 14:58:19 +13:00
|
|
|
var playlists = [];
|
2017-07-06 08:11:15 +12:00
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
// Spotify library items
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.props.spotify_library_playlists && (this.props.source == 'all' || this.props.source == 'spotify')){
|
2017-08-12 23:01:55 +12:00
|
|
|
for (var i = 0; i < this.props.spotify_library_playlists.length; i++){
|
|
|
|
|
var uri = this.props.spotify_library_playlists[i]
|
|
|
|
|
if (this.props.playlists.hasOwnProperty(uri)){
|
|
|
|
|
playlists.push(this.props.playlists[uri])
|
2017-07-06 08:11:15 +12:00
|
|
|
}
|
2017-01-13 13:17:47 +13:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-21 16:26:47 +13:00
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
// Mopidy library items
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.props.mopidy_library_playlists && (this.props.source == 'all' || this.props.source == 'local')){
|
2017-08-12 23:01:55 +12:00
|
|
|
for (var i = 0; i < this.props.mopidy_library_playlists.length; i++){
|
|
|
|
|
var uri = this.props.mopidy_library_playlists[i]
|
|
|
|
|
if (this.props.playlists.hasOwnProperty(uri)){
|
|
|
|
|
playlists.push(this.props.playlists[uri])
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-12-09 18:47:10 +13:00
|
|
|
}
|
|
|
|
|
|
2018-06-18 20:44:35 +12:00
|
|
|
if (this.props.sort){
|
|
|
|
|
playlists = helpers.sortItems(playlists, this.props.sort, this.props.sort_reverse);
|
|
|
|
|
}
|
2017-10-20 14:58:19 +13:00
|
|
|
playlists = helpers.removeDuplicates(playlists);
|
2017-08-12 23:01:55 +12:00
|
|
|
|
2017-08-14 20:02:41 +12:00
|
|
|
if (this.state.filter !== ''){
|
2017-10-20 14:58:19 +13:00
|
|
|
playlists = helpers.applyFilter('name', this.state.filter, playlists);
|
2017-08-14 20:02:41 +12:00
|
|
|
}
|
|
|
|
|
|
2017-10-20 14:58:19 +13:00
|
|
|
// Apply our lazy-load-rendering
|
|
|
|
|
var total_playlists = playlists.length;
|
|
|
|
|
playlists = playlists.slice(0, this.state.limit);
|
|
|
|
|
|
2017-08-12 23:01:55 +12:00
|
|
|
if (this.props.view == 'list'){
|
2018-06-17 13:27:01 +12:00
|
|
|
var columns = [
|
|
|
|
|
{
|
|
|
|
|
label: 'Name',
|
|
|
|
|
name: 'name'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Owner',
|
|
|
|
|
name: 'owner'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Tracks',
|
|
|
|
|
name: 'tracks_total'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Editable',
|
|
|
|
|
name: 'can_edit'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Source',
|
|
|
|
|
name: 'source'
|
|
|
|
|
}
|
|
|
|
|
];
|
2017-07-17 08:27:39 +12:00
|
|
|
|
2016-11-21 16:26:47 +13:00
|
|
|
return (
|
2017-06-18 05:47:36 +12:00
|
|
|
<section className="content-wrapper">
|
2017-02-02 09:06:15 +13:00
|
|
|
<List
|
|
|
|
|
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
|
|
|
|
rows={playlists}
|
|
|
|
|
columns={columns}
|
2017-03-13 21:19:09 +13:00
|
|
|
className="playlist-list"
|
2017-03-06 09:03:20 +13:00
|
|
|
link_prefix={global.baseURL+"playlist/"} />
|
2017-10-20 14:58:19 +13:00
|
|
|
<LazyLoadListener loading={this.state.limit < total_playlists} loadMore={() => this.setState({limit: this.state.limit + this.state.per_page})} />
|
2016-11-21 16:26:47 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
2017-10-10 13:32:04 +13:00
|
|
|
} else {
|
2016-11-21 16:26:47 +13:00
|
|
|
return (
|
2017-06-18 05:47:36 +12:00
|
|
|
<section className="content-wrapper">
|
2017-02-02 09:06:15 +13:00
|
|
|
<PlaylistGrid
|
|
|
|
|
handleContextMenu={(e,item) => this.handleContextMenu(e,item)}
|
|
|
|
|
playlists={playlists} />
|
2017-10-20 14:58:19 +13:00
|
|
|
<LazyLoadListener loading={this.state.limit < total_playlists} loadMore={() => this.setState({limit: this.state.limit + this.state.per_page})} />
|
2016-11-21 16:26:47 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
2017-08-14 20:02:41 +12:00
|
|
|
var source_options = [
|
2017-07-06 08:11:15 +12:00
|
|
|
{
|
|
|
|
|
value: 'all',
|
|
|
|
|
label: 'All'
|
|
|
|
|
},
|
|
|
|
|
{
|
2017-08-12 23:01:55 +12:00
|
|
|
value: 'local',
|
|
|
|
|
label: 'Local'
|
2018-02-06 19:54:55 +13:00
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
2018-08-05 20:59:11 +12:00
|
|
|
if (this.props.spotify_enabled){
|
2018-02-06 19:54:55 +13:00
|
|
|
source_options.push({
|
2017-08-12 23:01:55 +12:00
|
|
|
value: 'spotify',
|
|
|
|
|
label: 'Spotify'
|
2018-02-06 19:54:55 +13:00
|
|
|
});
|
|
|
|
|
}
|
2017-07-06 08:11:15 +12:00
|
|
|
|
2016-11-21 16:26:47 +13:00
|
|
|
var view_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'thumbnails',
|
|
|
|
|
label: 'Thumbnails'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'list',
|
|
|
|
|
label: 'List'
|
|
|
|
|
}
|
2018-02-06 19:54:55 +13:00
|
|
|
];
|
2016-11-02 21:23:35 +13:00
|
|
|
|
2016-12-09 18:47:10 +13:00
|
|
|
var sort_options = [
|
2018-06-18 20:44:35 +12:00
|
|
|
{
|
|
|
|
|
value: null,
|
|
|
|
|
label: 'Default'
|
|
|
|
|
},
|
2016-12-09 18:47:10 +13:00
|
|
|
{
|
|
|
|
|
value: 'name',
|
|
|
|
|
label: 'Name'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'can_edit',
|
|
|
|
|
label: 'Editable'
|
|
|
|
|
},
|
2016-12-14 09:13:47 +13:00
|
|
|
{
|
|
|
|
|
value: 'owner.id',
|
|
|
|
|
label: 'Owner'
|
|
|
|
|
},
|
2016-12-09 18:47:10 +13:00
|
|
|
{
|
|
|
|
|
value: 'tracks.total',
|
|
|
|
|
label: 'Tracks'
|
2017-02-03 09:04:47 +13:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'source',
|
|
|
|
|
label: 'Source'
|
2016-12-09 18:47:10 +13:00
|
|
|
}
|
2018-02-06 19:54:55 +13:00
|
|
|
];
|
2016-12-09 18:47:10 +13:00
|
|
|
|
2017-03-06 09:03:20 +13:00
|
|
|
var options = (
|
|
|
|
|
<span>
|
2018-05-06 20:25:59 +12:00
|
|
|
<FilterField
|
|
|
|
|
handleChange={value => this.setState({filter: value})}
|
|
|
|
|
/>
|
|
|
|
|
<DropdownField
|
|
|
|
|
icon="sort"
|
|
|
|
|
name="Sort"
|
|
|
|
|
value={this.props.sort}
|
|
|
|
|
options={sort_options}
|
2018-06-18 20:44:35 +12:00
|
|
|
selected_icon={this.props.sort ? (this.props.sort_reverse ? 'keyboard_arrow_up' : 'keyboard_arrow_down') : null}
|
2018-05-06 20:25:59 +12:00
|
|
|
handleChange={value => {this.setSort(value); this.props.uiActions.hideContextMenu() }}
|
|
|
|
|
/>
|
|
|
|
|
<DropdownField
|
2018-05-16 16:50:46 +12:00
|
|
|
icon="visibility"
|
2018-05-06 20:25:59 +12:00
|
|
|
name="View"
|
|
|
|
|
value={this.props.view}
|
|
|
|
|
options={view_options}
|
|
|
|
|
handleChange={value => {this.props.uiActions.set({ library_playlists_view: value}); this.props.uiActions.hideContextMenu() }}
|
|
|
|
|
/>
|
|
|
|
|
<DropdownField
|
2018-05-16 16:50:46 +12:00
|
|
|
icon="cloud"
|
2018-05-06 20:25:59 +12:00
|
|
|
name="Source"
|
|
|
|
|
value={this.props.source}
|
|
|
|
|
options={source_options}
|
|
|
|
|
handleChange={value => {this.props.uiActions.set({ library_playlists_source: value}); this.props.uiActions.hideContextMenu() }}
|
|
|
|
|
/>
|
2018-07-09 19:09:12 +12:00
|
|
|
<Link className="button no-hover" to={global.baseURL+'playlist/create'}>
|
2018-05-16 21:08:45 +12:00
|
|
|
<Icon name="add_box" />New
|
2018-07-09 19:09:12 +12:00
|
|
|
</Link>
|
2017-03-06 09:03:20 +13:00
|
|
|
</span>
|
2016-11-14 17:32:36 +13:00
|
|
|
)
|
|
|
|
|
|
2016-10-21 23:27:50 +13:00
|
|
|
return (
|
2016-10-26 16:55:47 +13:00
|
|
|
<div className="view library-playlists-view">
|
2018-05-15 21:30:57 +12:00
|
|
|
<Header options={options} uiActions={this.props.uiActions}>
|
|
|
|
|
<Icon name="queue_music" type="material" />
|
|
|
|
|
My playlists
|
|
|
|
|
</Header>
|
2016-11-21 16:26:47 +13:00
|
|
|
{ this.renderView() }
|
2016-10-21 23:27:50 +13:00
|
|
|
</div>
|
|
|
|
|
)
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Export our component
|
|
|
|
|
*
|
|
|
|
|
* We also integrate our global store, using connect()
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
2016-11-10 10:26:15 +13:00
|
|
|
return {
|
2017-08-23 07:39:33 +12:00
|
|
|
slim_mode: state.ui.slim_mode,
|
2017-08-11 08:08:03 +12:00
|
|
|
mopidy_connected: state.mopidy.connected,
|
2018-02-06 19:54:55 +13:00
|
|
|
mopidy_uri_schemes: state.mopidy.uri_schemes,
|
2017-08-12 23:01:55 +12:00
|
|
|
mopidy_library_playlists: state.mopidy.library_playlists,
|
2017-11-12 09:05:34 +13:00
|
|
|
mopidy_library_playlists_status: (state.ui.processes.MOPIDY_LIBRARY_PLAYLISTS_PROCESSOR !== undefined ? state.ui.processes.MOPIDY_LIBRARY_PLAYLISTS_PROCESSOR.status : null),
|
2018-08-05 20:59:11 +12:00
|
|
|
spotify_enabled: (state.mopidy.uri_schemes && state.mopidy.uri_schemes.includes('spotify:')),
|
2017-08-12 23:01:55 +12:00
|
|
|
spotify_library_playlists: state.spotify.library_playlists,
|
2017-11-12 09:05:34 +13:00
|
|
|
spotify_library_playlists_status: (state.ui.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR !== undefined ? state.ui.processes.SPOTIFY_GET_LIBRARY_PLAYLISTS_PROCESSOR.status : null),
|
2017-05-22 04:19:44 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-09-27 15:29:17 +13:00
|
|
|
me_id: (state.spotify.me ? state.spotify.me.id : false),
|
2017-08-02 21:11:22 +12:00
|
|
|
view: state.ui.library_playlists_view,
|
2017-08-14 20:02:41 +12:00
|
|
|
source: (state.ui.library_playlists_source ? state.ui.library_playlists_source : 'all'),
|
2018-06-18 20:44:35 +12:00
|
|
|
sort: (state.ui.library_playlists_sort ? state.ui.library_playlists_sort : null),
|
|
|
|
|
sort_reverse: (state.ui.library_playlists_sort_reverse ? state.ui.library_playlists_sort_reverse : false),
|
2017-08-02 10:53:30 +12:00
|
|
|
playlists: state.core.playlists
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 11:20:02 +13:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
2017-08-11 21:59:14 +12:00
|
|
|
coreActions: bindActionCreators(coreActions, dispatch),
|
2016-11-14 11:20:02 +13:00
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryPlaylists)
|