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 <[email protected]>
  • Loading branch information
hamza221 committed Aug 9, 2024
1 parent 01fa7a3 commit db4314c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions js/viewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/viewer-main.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

11 changes: 8 additions & 3 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 Expand Up @@ -139,4 +144,4 @@ function getDavPath({ filename, basename, source = '' }: { filename: string, bas
return getRootPath() + encodePath(filename)
}

export { extractFilePaths, sortCompare, genFileInfo, getDavPath }
export { extractFilePaths, sortCompare, genFileInfo, getDavPath }

Check failure on line 147 in src/utils/fileUtils.ts

View workflow job for this annotation

GitHub Actions / NPM lint

Newline required at end of file but not found

0 comments on commit db4314c

Please sign in to comment.