-
Notifications
You must be signed in to change notification settings - Fork 116
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(archive): Folders come before files when sorting #1171
Conversation
mxiao6
commented
Feb 5, 2020
Verified that @mxiao6 has signed the CLA. Thanks for the pull request! |
} | ||
|
||
// folders always come before files | ||
sortedItems.sort((a, b) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we should be able to collapse all of this into a single .sort
call, with sortDirection
controlling the comparator logic. Can we also check to see how webapp does this sorting? I don't see an equivalent complex sort function there.
@@ -180,17 +185,15 @@ class ArchiveExplorer extends React.Component { | |||
} | |||
|
|||
if (typeof aItem === 'number' && typeof bItem === 'number') { | |||
return aItem - bItem; | |||
return sortDirection === SortDirection.ASC ? aItem - bItem : bItem - aItem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about flipping them at assignment to avoid the repeated logic?
const aItem = sortDirection === SortDirection.ASC ? a : b;
const bItem = sortdirection === SortDirection.ASC ? b : a;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about flipping them at assignment to avoid the repeated logic?
const aItem = sortDirection === SortDirection.ASC ? a : b; const bItem = sortdirection === SortDirection.ASC ? b : a;
Cannot flip them before null
check below, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job.