Playlists sorting; Default to by name
This commit is contained in:
3
src/js/bootstrap.js
vendored
3
src/js/bootstrap.js
vendored
@ -50,7 +50,8 @@ var initialState = {
|
||||
spotify: {
|
||||
connected: false,
|
||||
country: 'NZ',
|
||||
locale: 'en_NZ'
|
||||
locale: 'en_NZ',
|
||||
me: false
|
||||
},
|
||||
ui: {
|
||||
context_menu: {
|
||||
|
||||
@ -255,24 +255,33 @@ export let createRange = function (indexes){
|
||||
* @return array
|
||||
**/
|
||||
export let sortItems = function (array, property, reverse = false){
|
||||
|
||||
function compare(a,b) {
|
||||
|
||||
var a_value = a
|
||||
var a_property_split = property.split('.')
|
||||
for( var i = 0; i < a_property_split.length; i++ ){
|
||||
if( typeof(a_value[a_property_split[i]]) === 'undefined' ) return -1
|
||||
a_value = a_value[a_property_split[i]]
|
||||
if( typeof(a_value[a_property_split[i]]) === 'undefined' ){
|
||||
a_value = false
|
||||
}else{
|
||||
a_value = a_value[a_property_split[i]]
|
||||
}
|
||||
}
|
||||
|
||||
var b_value = b
|
||||
var b_property_split = property.split('.')
|
||||
for( var i = 0; i < b_property_split.length; i++ ){
|
||||
if( typeof(b_value[b_property_split[i]]) === 'undefined' ) return -1
|
||||
b_value = b_value[b_property_split[i]]
|
||||
if( typeof(b_value[b_property_split[i]]) === 'undefined' ){
|
||||
b_value = false
|
||||
}else{
|
||||
b_value = b_value[b_property_split[i]]
|
||||
}
|
||||
}
|
||||
|
||||
if( typeof(a_value) === 'boolean'){
|
||||
return a_value
|
||||
if( a_value && !b_value ) return -1
|
||||
if( !a_value && b_value ) return 1
|
||||
return 0
|
||||
|
||||
}else if( typeof(a_value) === 'string'){
|
||||
if(a_value.toLowerCase() > b_value.toLowerCase()) return 1
|
||||
@ -280,7 +289,8 @@ export let sortItems = function (array, property, reverse = false){
|
||||
|
||||
}else{
|
||||
if( parseInt(a_value) > parseInt(b_value) ) return 1
|
||||
return -1
|
||||
if( parseInt(a_value) < parseInt(b_value) ) return -1
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -312,6 +312,7 @@ export default function reducer(ui = {}, action){
|
||||
if( !action.data ) return ui
|
||||
var playlists = [...ui.playlists, ...action.data]
|
||||
playlists = helpers.mergeDuplicates(playlists, 'uri')
|
||||
helpers.sortItems(playlists, 'name')
|
||||
return Object.assign({}, ui, {
|
||||
playlists: playlists
|
||||
});
|
||||
|
||||
@ -35,7 +35,7 @@ class LibraryPlaylists extends React.Component{
|
||||
renderView(){
|
||||
if( !this.props.playlists ) return null
|
||||
|
||||
var playlists = this.props.playlists
|
||||
var playlists = Object.assign([], this.props.playlists)
|
||||
if( this.props.sort ){
|
||||
playlists = helpers.sortItems(playlists, this.props.sort, this.props.sort_reverse)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user