Skip to content

Commit

Permalink
Fix: sorting by date and number
Browse files Browse the repository at this point in the history
Signed-off-by: Hamza Mahjoubi <hamzamahjoubi221@gmail.com>

[skip ci]
  • Loading branch information
hamza221 authored and backportbot[bot] committed May 23, 2024
1 parent 6dd5c4c commit 086c9c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/index-BahqIHTU.mjs.map

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions src/utils/fileUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {

// if this is a number, let's sort by integer
if (isNumber(fileInfo1[key]) && isNumber(fileInfo2[key])) {
return Number(fileInfo1[key]) - Number(fileInfo2[key])
const result = Number(fileInfo1[key]) - Number(fileInfo2[key])
return asc ? result : -result
}

// else we sort by string, so let's sort directories first
Expand All @@ -70,7 +71,11 @@ const sortCompare = function(fileInfo1, fileInfo2, key, asc = true) {
} else if (fileInfo1.type !== 'directory' && fileInfo2.type === 'directory') {
return 1
}

// sort by date if key is lastmod
if (key === 'lastmod') {
const result = new Date(fileInfo1[key]).getTime() - new Date(fileInfo2[key]).getTime()
return asc ? -result : result
}
// finally sort by name
return asc
? fileInfo1[key].localeCompare(fileInfo2[key], OC.getLanguage(), { numeric: true })
Expand Down

0 comments on commit 086c9c0

Please sign in to comment.