Default to string-based sorting, check both a_ and b_values before deciding sort mechanic

This commit is contained in:
James Barnsley
2019-04-10 15:23:16 +12:00
parent 4e93234d12
commit bd3bf89150
4 changed files with 23 additions and 38 deletions

View File

@ -1764,35 +1764,34 @@ var sortItems = exports.sortItems = function sortItems(array, property) {
// 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;
}
}
@ -84370,12 +84369,6 @@ var LibraryAlbums = function (_React$Component) {
return LibraryAlbums;
}(_react2.default.Component);
/**
* Export our component
*
* We also integrate our global store, using connect()
**/
var mapStateToProps = function mapStateToProps(state, ownProps) {
return {
mopidy_connected: state.mopidy.connected,

File diff suppressed because one or more lines are too long

View File

@ -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
}
}

View File

@ -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,