My Files: Fix sorting comparison functions

- Properly distinguish between < and = cases
 - Make a copy before sorting (this wasn't causing problems; just good
   practice)
This commit is contained in:
Alex Liebowitz 2017-02-24 00:32:32 -05:00
parent 4ac007bbf6
commit d3666b119f
2 changed files with 22 additions and 8 deletions

View file

@ -21,7 +21,7 @@ Web UI version numbers should always match the corresponding version of LBRY App
* On load screen, always show Cancel link if a previous page is available * On load screen, always show Cancel link if a previous page is available
* When user hits "Watch," don't check balance if download already started * When user hits "Watch," don't check balance if download already started
* Restore UI version on Help page * Restore UI version on Help page
* * Fix sorting on My Files page
## [0.9.0rc9] - 2017-02-22 ## [0.9.0rc9] - 2017-02-22
### Changed ### Changed

View file

@ -133,18 +133,32 @@ export let FileListPublished = React.createClass({
export let FileList = React.createClass({ export let FileList = React.createClass({
_sortFunctions: { _sortFunctions: {
date: function(fileInfos) { date: function(fileInfos) {
return fileInfos.reverse(); return fileInfos.slice().reverse();
}, },
title: function(fileInfos) { title: function(fileInfos) {
return fileInfos.sort(function(a, b) { return fileInfos.slice().sort(function(fileInfo1, fileInfo2) {
return ((a.metadata ? a.metadata.title.toLowerCase() : a.name) > const title1 = fileInfo1.metadata ? fileInfo1.metadata.title.toLowerCase() : fileInfo1.name;
(b.metadata ? b.metadata.title.toLowerCase() : b.name)); const title2 = fileInfo2.metadata ? fileInfo2.metadata.title.toLowerCase() : fileInfo2.name;
if (title1 < title2) {
return -1;
} else if (title1 > title2) {
return 1;
} else {
return 0;
}
}); });
}, },
filename: function(fileInfos) { filename: function(fileInfos) {
return fileInfos.sort(function(a, b) { return fileInfos.slice().sort(function({file_name: fileName1}, {file_name: fileName2}) {
return (a.file_name.toLowerCase() > const fileName1Lower = fileName1.toLowerCase();
b.file_name.toLowerCase()); const fileName2Lower = fileName2.toLowerCase();
if (fileName1Lower < fileName2Lower) {
return -1;
} else if (fileName2Lower > fileName1Lower) {
return 1;
} else {
return 0;
}
}); });
}, },
}, },