Files
Iris/src/js/views/library/LibraryPlaylists.js

156 lines
3.6 KiB
JavaScript
Raw Normal View History

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-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'
import Header from '../../components/Header'
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'
import * as mopidyActions from '../../services/mopidy/actions'
import * as spotifyActions from '../../services/spotify/actions'
class LibraryPlaylists extends React.Component{
constructor(props) {
super(props);
}
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(){
if( !this.props.playlists ) return null
2016-11-21 16:26:47 +13:00
2016-12-14 08:51:11 +13:00
var playlists = Object.assign([], this.props.playlists)
2016-12-09 18:47:10 +13:00
if( this.props.sort ){
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' ){
var columns = [
{
width: 30,
label: 'Name',
name: 'name'
},
{
width: 30,
label: 'Owner',
name: 'owner'
2016-11-21 16:26:47 +13:00
},
{
width: 10,
label: 'Can edit',
name: 'can_edit'
},
{
width: 10,
label: 'Tracks',
name: 'tracks.total'
}
]
return (
<section className="list-wrapper">
2016-12-09 18:47:10 +13:00
<List rows={playlists} columns={columns} link_prefix="/playlist/" show_source_icon={true} />
2016-11-21 16:26:47 +13:00
</section>
)
}else{
return (
<section className="grid-wrapper">
2016-12-14 10:51:19 +13:00
<PlaylistGrid playlists={playlists} />
2016-11-21 16:26:47 +13:00
</section>
)
}
}
render(){
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'
},
{
value: 'owner.id',
label: 'Owner'
},
2016-12-09 18:47:10 +13:00
{
value: 'tracks.total',
label: 'Tracks'
}
]
2016-11-14 17:32:36 +13:00
var actions = (
2016-11-21 16:26:47 +13:00
<div>
<DropdownField icon="sort" name="Sort" value={ this.props.sort } options={ sort_options } handleChange={ value => this.setSort(value) } />
2016-12-09 18:47:10 +13:00
<DropdownField icon="eye" name="View" value={ this.props.view } options={ view_options } handleChange={ value => this.props.uiActions.set({ library_playlists_view: value }) } />
2016-11-21 16:26:47 +13:00
<button onClick={ () => this.props.uiActions.openModal('create_playlist', {} ) }>
<FontAwesome name="plus" />&nbsp;
New
</button>
</div>
2016-11-14 17:32:36 +13:00
)
return (
2016-10-26 16:55:47 +13:00
<div className="view library-playlists-view">
2016-11-14 17:32:36 +13:00
<Header icon="playlist" title="My playlists" actions={actions} />
2016-11-21 16:26:47 +13:00
{ this.renderView() }
</div>
)
}
}
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
const mapStateToProps = (state, ownProps) => {
return {
2016-11-21 16:26:47 +13:00
view: state.ui.library_playlists_view,
2016-12-09 18:47:10 +13:00
sort: state.ui.library_playlists_sort,
sort_reverse: state.ui.library_playlists_sort_reverse,
playlists: state.ui.playlists
}
}
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)