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-11-14 11:20:02 +13:00
|
|
|
import FontAwesome from 'react-fontawesome'
|
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'
|
|
|
|
|
import DropdownField from '../../components/DropdownField'
|
2016-10-23 23:48:06 +13:00
|
|
|
import Header from '../../components/Header'
|
2016-10-21 23:27:50 +13:00
|
|
|
|
2016-12-09 18:47:10 +13:00
|
|
|
import * as helpers from '../../helpers'
|
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
|
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
|
if( this.props.sort == value ) reverse = !this.props.sort_reverse
|
|
|
|
|
|
|
|
|
|
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-05-22 04:19:44 +12:00
|
|
|
if (helpers.isLoading(this.props.load_queue,['spotify_me/playlists'])){
|
|
|
|
|
return (
|
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>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!this.props.library_playlists || !this.props.playlists ){
|
|
|
|
|
return null
|
|
|
|
|
}
|
2017-01-13 13:17:47 +13:00
|
|
|
|
|
|
|
|
var playlists = []
|
|
|
|
|
for (var i = 0; i < this.props.library_playlists.length; i++){
|
|
|
|
|
var uri = this.props.library_playlists[i]
|
2017-07-06 08:11:15 +12:00
|
|
|
var owner_id = helpers.getFromUri('playlistowner',uri)
|
|
|
|
|
|
2017-01-13 13:17:47 +13:00
|
|
|
if (this.props.playlists.hasOwnProperty(uri)){
|
2017-07-06 08:11:15 +12:00
|
|
|
|
|
|
|
|
switch (this.props.filter){
|
|
|
|
|
|
|
|
|
|
case 'only_mine':
|
|
|
|
|
if (this.props.me_id && owner_id == this.props.me_id){
|
|
|
|
|
playlists.push(this.props.playlists[uri])
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
case 'only_others':
|
|
|
|
|
if (!this.props.me_id || owner_id != this.props.me_id){
|
|
|
|
|
playlists.push(this.props.playlists[uri])
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
playlists.push(this.props.playlists[uri])
|
|
|
|
|
break
|
|
|
|
|
}
|
2017-01-13 13:17:47 +13:00
|
|
|
}
|
|
|
|
|
}
|
2016-11-21 16:26:47 +13:00
|
|
|
|
2016-12-09 18:47:10 +13:00
|
|
|
if( this.props.sort ){
|
2016-12-12 09:07:47 +13:00
|
|
|
playlists = helpers.sortItems(playlists, this.props.sort, this.props.sort_reverse)
|
2016-12-09 18:47:10 +13:00
|
|
|
}
|
|
|
|
|
|
2016-11-21 16:26:47 +13:00
|
|
|
if( this.props.view == 'list' ){
|
2017-07-17 08:27:39 +12:00
|
|
|
if (this.props.slim_mode){
|
|
|
|
|
var columns = [
|
|
|
|
|
{
|
|
|
|
|
label: 'Name',
|
|
|
|
|
name: 'name'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Tracks',
|
|
|
|
|
name: 'tracks_total'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
} else {
|
|
|
|
|
var columns = [
|
|
|
|
|
{
|
|
|
|
|
label: 'Name',
|
|
|
|
|
name: 'name'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Owner',
|
|
|
|
|
name: 'owner'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Tracks',
|
|
|
|
|
name: 'tracks_total'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
label: 'Editable',
|
|
|
|
|
name: 'can_edit'
|
2017-08-07 21:34:33 +12:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
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/"} />
|
2016-11-21 16:26:47 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}else{
|
|
|
|
|
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} />
|
2016-11-21 16:26:47 +13:00
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
render(){
|
|
|
|
|
|
2017-07-06 08:11:15 +12:00
|
|
|
var filter_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'all',
|
|
|
|
|
label: 'All'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'only_mine',
|
|
|
|
|
label: 'Owned by me'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'only_others',
|
|
|
|
|
label: 'I\'m following'
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2016-11-21 16:26:47 +13:00
|
|
|
var view_options = [
|
|
|
|
|
{
|
|
|
|
|
value: 'thumbnails',
|
|
|
|
|
label: 'Thumbnails'
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
value: 'list',
|
|
|
|
|
label: 'List'
|
|
|
|
|
}
|
2016-11-02 21:23:35 +13:00
|
|
|
]
|
|
|
|
|
|
2016-12-09 18:47:10 +13:00
|
|
|
var sort_options = [
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
|
2017-03-06 09:03:20 +13:00
|
|
|
var options = (
|
|
|
|
|
<span>
|
2017-07-06 08:11:15 +12:00
|
|
|
<DropdownField icon="filter" name="Filter" value={this.props.filter} options={filter_options} handleChange={val => {this.props.uiActions.set({ library_playlists_filter: val}); this.props.uiActions.hideContextMenu() }} />
|
2017-03-06 09:03:20 +13:00
|
|
|
<DropdownField icon="sort" name="Sort" value={this.props.sort} options={sort_options} reverse={this.props.sort_reverse} handleChange={val => {this.setSort(val); this.props.uiActions.hideContextMenu() }} />
|
|
|
|
|
<DropdownField icon="eye" name="View" value={this.props.view} options={view_options} handleChange={val => {this.props.uiActions.set({ library_playlists_view: val}); this.props.uiActions.hideContextMenu() }} />
|
2017-07-14 08:47:02 +12:00
|
|
|
<button className="no-hover" onClick={ () => this.props.uiActions.openModal('create_playlist', {} ) }>
|
2016-11-21 16:26:47 +13:00
|
|
|
<FontAwesome name="plus" />
|
|
|
|
|
New
|
|
|
|
|
</button>
|
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">
|
2017-03-06 09:03:20 +13:00
|
|
|
<Header icon="playlist" title="My playlists" options={options} uiActions={this.props.uiActions} />
|
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-07-17 08:27:39 +12:00
|
|
|
slim_mode: state.ui.slim_mode,
|
2017-05-22 04:19:44 +12:00
|
|
|
load_queue: state.ui.load_queue,
|
2017-07-06 08:11:15 +12:00
|
|
|
me_id: (state.spotify.me ? state.spotify.me.id : (state.ui.config && state.ui.config.spotify_username ? state.ui.config.spotify_username : false)),
|
2017-08-02 21:11:22 +12:00
|
|
|
view: state.ui.library_playlists_view,
|
|
|
|
|
filter: (state.ui.library_playlists_filter ? state.ui.library_playlists_filter : 'all'),
|
|
|
|
|
sort: (state.ui.library_playlists_sort ? state.ui.library_playlists_sort : 'name'),
|
|
|
|
|
sort_reverse: (state.ui.library_playlists_sort_reverse ? true : false),
|
2017-08-02 10:53:30 +12:00
|
|
|
library_playlists: state.core.library_playlists,
|
|
|
|
|
playlists: state.core.playlists
|
2016-10-17 10:39:11 +13:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 11:20:02 +13:00
|
|
|
const mapDispatchToProps = (dispatch) => {
|
|
|
|
|
return {
|
|
|
|
|
uiActions: bindActionCreators(uiActions, dispatch),
|
|
|
|
|
mopidyActions: bindActionCreators(mopidyActions, dispatch),
|
|
|
|
|
spotifyActions: bindActionCreators(spotifyActions, dispatch)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(LibraryPlaylists)
|