Default to string-based sorting, check both a_ and b_values before deciding sort mechanic
This commit is contained in:
@ -1313,35 +1313,34 @@ export let sortItems = function (array, property, reverse = false, sort_map = nu
|
||||
// Map sorting
|
||||
// Use the index of the string as a sorting mechanism
|
||||
if (sort_map){
|
||||
|
||||
var a_index = sort_map.indexOf(a_value+':');
|
||||
var b_index = sort_map.indexOf(b_value+':');
|
||||
if (a_index < b_index) return 1;
|
||||
if (a_index > b_index) return -1;
|
||||
|
||||
// Boolean sorting
|
||||
} else if (typeof(a_value) === 'boolean'){
|
||||
} else if (typeof a_value == 'boolean' && typeof b_value == 'boolean'){
|
||||
if (a_value && !b_value) return -1;
|
||||
if (!a_value && b_value) return 1;
|
||||
return 0
|
||||
|
||||
// Alphabetic sorting
|
||||
} else if (typeof(a_value) === 'string'){
|
||||
if (a_value && !b_value ) return -1;
|
||||
if (!a_value && b_value ) return 1;
|
||||
if (!a_value && !b_value ) return 0;
|
||||
if (a_value.toLowerCase() > b_value.toLowerCase()) return 1;
|
||||
if (a_value.toLowerCase() < b_value.toLowerCase()) return -1;
|
||||
return 0
|
||||
|
||||
// Numeric sorting
|
||||
} else {
|
||||
} else if (typeof a_value == 'number' && typeof b_value == 'number'){
|
||||
if (a_value == null && b_value == null) return 0;
|
||||
if (a_value == null) return -1;
|
||||
if (b_value == null) return 1;
|
||||
if (parseInt(a_value) > parseInt(b_value)) return 1;
|
||||
if (parseInt(a_value) < parseInt(b_value)) return -1;
|
||||
return 0
|
||||
|
||||
// Alphabetic sorting
|
||||
} else {
|
||||
if (a_value && !b_value ) return -1;
|
||||
if (!a_value && b_value ) return 1;
|
||||
if (!a_value && !b_value ) return 0;
|
||||
if (a_value.toLowerCase() > b_value.toLowerCase()) return 1;
|
||||
if (a_value.toLowerCase() < b_value.toLowerCase()) return -1;
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -350,13 +350,6 @@ class LibraryAlbums extends React.Component{
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Export our component
|
||||
*
|
||||
* We also integrate our global store, using connect()
|
||||
**/
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
return {
|
||||
mopidy_connected: state.mopidy.connected,
|
||||
|
||||
Reference in New Issue
Block a user