Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use localeCompare to sort files #977

Merged
merged 5 commits into from
Feb 28, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions src/bundles/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ export const sorts = {
BY_SIZE: 'size'
}

function compare (a, b, asc) {
const strings = typeof a === 'string' && typeof b === 'string'

if (strings ? a.toLowerCase() > b.toLowerCase() : a > b) {
return asc ? 1 : -1
} else if (strings ? a.toLowerCase() < b.toLowerCase() : a < b) {
return asc ? -1 : 1
} else {
return 0
}
}

const make = (basename, action) => (...args) => async (args2) => {
const id = Symbol(basename)
const { dispatch, getIpfs, store } = args2
Expand Down Expand Up @@ -361,9 +349,23 @@ export default (opts = {}) => {
content: pageContent.content.sort((a, b) => {
if (a.type === b.type || isMac) {
if (sorting.by === sorts.BY_NAME) {
return compare(a.name, b.name, sorting.asc)
a = a.name
b = b.name

return sorting.asc
? a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' })
fsdiogo marked this conversation as resolved.
Show resolved Hide resolved
: b.localeCompare(a, undefined, { numeric: true, sensitivity: 'base' })
} else {
return compare(a.cumulativeSize || a.size, b.cumulativeSize || b.size, sorting.asc)
a = a.cumulativeSize || a.size
b = b.cumulativeSize || b.size

if (a > b) {
return sorting.asc ? 1 : -1
} else if (a < b) {
return sorting.asc ? -1 : 1
} else {
return 0
}
}
}

Expand Down