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
feat: sort files by name using locale compare(#196) #198
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/kimlimjustin/xplorer/CGZ9MpuHNkDggbiy9PC6JToDFEdt |
@kimlimjustin I'm new to this 😂 What can I do with it or should I wait? |
The code is ready, please give it a try and tell me whether this PR looks good and meets what you expected, or otherwise comment which place can be improved or something. You can go to the |
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.
files.sort((a, b) => {
if (sort === 'A') {
return compator(a.basename.toLowerCase(), b.basename.toLowerCase());
} else {
return compator(b.basename.toLowerCase(), a.basename.toLowerCase());
}
});
src/Components/Open/displayFiles.ts
Outdated
if (sort === 'A' || sort === 'Z') { | ||
const compator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' }).compare; | ||
files.sort((a, b) => { | ||
if (sort === '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.
Avoid unnecessary conditional statement inside sort function to enhance performance:
if (sort === 'A') {
files.sort((a, b) => compator(a.basename.toLowerCase(), b.basename.toLowerCase());
} else {
files.sort((a, b) => compator(b.basename.toLowerCase(), a.basename.toLowerCase());
}
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.
Idk why there're so many tabs I'm confused 🤣 What do you think about using space?
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.
Idk why there're so many tabs I'm confused 🤣 What do you think about using space?
Actually, it's intended to prettier it lol, when you code and save Xplorer code on VSCode, it'll auto format it using prettier.
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.
Ok just I'm more used to space. Tab is fine on VSCode as you can set its width but on Github it's not too good. Bad boy Github 🤣
You can setup prettier to use space tho, but it'd be a tremendous change to all the code lol.
You haven't implemented sorting on size reversed. Maybe you can add letter |
…al statement inside sort function Co-authored-by: uahnbu <qaqqyl@gmail.com>
Yep, I think will be implemented together with the title bar you said at #193, could you please open an issue regarding this so that I won't forget it. (but can't do it really soon too, need to wait until the end of this month when it's holiday so I can have time) |
commit 349187f Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 23 14:45:56 2021 +0700 fix: opening some directory crashes xplorer commit 288bdff Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 23 14:42:04 2021 +0700 feat: simplify the process to set Xplorer as default file explorer (Windows) (#203) * feat: simplify the process to set Xplorer as default file explorer (windows) * locales: pull locales from crowdin commit c85372e Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 23:38:56 2021 +0700 fix: broken `reveal` tag commit 1cce487 Merge: 8d228d1 b9fe970 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 21:48:45 2021 +0700 Merge pull request #201 from kimlimjustin/feat/extensions feat: custom theme extension commit 8d228d1 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 20:03:14 2021 +0700 chore: add open collective sponsor option commit b9fe970 Merge: e9a8a22 cd993a2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 15:08:04 2021 +0700 Merge branch 'master' into feat/extensions commit e9a8a22 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 15:04:55 2021 +0700 feat: automatically apply theme on install commit cd993a2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 14:33:37 2021 +0700 docs: introduce new xplorer domain (https://xplorer.space) commit c46dd92 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 22 14:16:04 2021 +0700 feat: updater for Xplorer commit 24501a4 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 21:38:52 2021 +0700 Revert "refactor<chore>: remove build workflow workaround as it's been fixed on Tauri" This reverts commit b7db463. commit 543c360 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 21:35:59 2021 +0700 fix: double click is set as default to open files/dirs when there is no preference set commit 9432bed Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 20:31:35 2021 +0700 fix: double click is set as default to click sidebar item when there is no preference set commit b7db463 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 20:11:41 2021 +0700 refactor<chore>: remove build workflow workaround as it's been fixed on Tauri commit 871a08a Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 19:23:21 2021 +0700 feat: install extensions from url commit 1fa883a Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 16:59:42 2021 +0700 refactor: make bundled xplorer extension output as new file extension (`.xtension) commit 9d313d5 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 11:27:55 2021 +0700 refactor: remove useless imports commit 8ffb58f Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 21 11:26:48 2021 +0700 feat: install packages extensions by reading its type and add uninstall extension feature commit 2b4c16a Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Mon Dec 20 17:53:20 2021 +0700 chore: add funding commit c15df60 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Dec 19 16:04:39 2021 +0700 fix: buggy GitPod environment on first load commit 14c993f Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Dec 19 15:15:48 2021 +0700 fix: icon not loaded on home files when first opening on linux commit ab142d8 Merge: bb931a3 216f7f2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 18 21:51:46 2021 +0700 Merge branch 'master' into feat/extensions commit 216f7f2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 18 21:24:00 2021 +0700 fix: improper image hover preview (resolve #200) commit bb931a3 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 18 19:19:32 2021 +0700 feat: install custom theme commit c566774 Merge: 0bd18e5 9852de2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 17 17:47:42 2021 +0700 Merge pull request #199 from kimlimjustin/feat/lnk feat: add support for `lnk` files commit 0bd18e5 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 16 11:07:07 2021 +0700 refactor<ci>: make rust tests run on pull request commit 9852de2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 16 10:46:13 2021 +0700 feat: add support for `lnk` files commit eb79f81 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 15 20:13:26 2021 +0700 refactor: remove unused import and variable commit e3a7755 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 15 19:53:18 2021 +0700 refactor: new way to customize theme commit 59251e6 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Dec 12 12:57:34 2021 +0700 feat: sort files by name using locale compare(#196) (#198) * feat: sort files by name using localeCompare (#196) * refactor: avoid conditional statement on sorting A-Z and Z-A * refactor: make sort inside conditional statement instead of conditional statement inside sort function Co-authored-by: uahnbu <qaqqyl@gmail.com> * fix: typescript compiled failed Co-authored-by: uahnbu <qaqqyl@gmail.com> commit 1381f04 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 11 16:31:42 2021 +0700 refactor<gp>: make gitpod works with tauri (#197) * refactor<gp>: make gitpod works with tauri * docs: update gitpod instruction commit 9929f35 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 10 17:43:12 2021 +0700 fix: app crashes when favorites path is null commit c193ec7 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 10 13:50:32 2021 +0700 docs: not functioning in Gitpod notice commit 24798ae Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 10 09:31:00 2021 +0700 feat: make programming language highlights customizable commit ef81720 Merge: 73fa528 6a63bcf Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 9 21:09:31 2021 +0700 Merge branch 'master' into feat/extensions commit 6a63bcf Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 9 20:00:59 2021 +0700 feat: add preference option to open dir/file by single clicking it commit 6f9239c Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 9 13:38:33 2021 +0700 feat: remove english language diacritics for instant search function commit 5dd9859 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 8 14:59:35 2021 +0700 feat: search for the next file if user type the same input for instant search with the previous commit 2a1dc71 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 8 07:58:07 2021 +0700 refactor: make search state reset timer as 750ms (#193) commit 107f2ff Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 7 20:31:07 2021 +0700 fix: buggy file selection commit 0b2a673 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Dec 7 20:08:19 2021 +0700 feat: ensure scrollbar is updated when selecting files commit 73fa528 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Mon Dec 6 20:20:04 2021 +0700 feat: build theme extension into a dist file commit 10007b0 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Mon Dec 6 19:38:26 2021 +0700 feat: search and select file/folder name by typing its starting letter (#191) commit ba770d0 Merge: 936492b 14e42ff Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Dec 5 12:27:13 2021 +0700 Merge branch 'master' into feat/extensions commit 14e42ff Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Dec 5 12:12:04 2021 +0700 feat: add ability to automatically change the preview file according to file selected commit 71cc612 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Dec 5 11:57:59 2021 +0700 feat: `ctrl/cmd + o` close the preview pane if the pane is already opened (#191) commit a962470 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 4 19:22:47 2021 +0700 fix: broken preview `txt` file commit 2b130d2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 4 17:33:47 2021 +0700 fix: scrollable context menu remember its position (#186 (comment)) commit e508a32 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sat Dec 4 17:22:50 2021 +0700 fix: read directory returned error when there is no preference set commit 5e5b4a6 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 3 20:12:54 2021 +0700 fix: broken tests commit 5634675 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 3 19:36:15 2021 +0700 fix: (right) clicking on certain area giving error commit 9949e04 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 3 19:28:37 2021 +0700 feat: make context menu scrollable when it's overflow (#186) commit 1b5a269 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Fri Dec 3 17:31:11 2021 +0700 fix: bunch of errors when preference/appearance is null commit 936492b Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 2 20:58:15 2021 +0700 Merge branch 'master' into feat/extensions commit 05f5111 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 2 20:42:16 2021 +0700 feat: add transparent effect options (blur, acrylic, none) commit dd4e208 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Thu Dec 2 19:44:56 2021 +0700 refactor: use serde on Rust instead of JSON class on JavaScript commit 0890e93 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 1 20:26:29 2021 +0700 fix<styles>: grid background become transparent after stop hovering it and update grid background color for `light+` theme commit a7f1c1c Merge: ec12eb2 9fd7734 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Wed Dec 1 19:39:42 2021 +0700 Merge pull request #187 from kimlimjustin/refactor/styles Minor improvement for `select` and `hover` styling commit 9fd7734 Merge: f044269 ec12eb2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Nov 30 17:36:15 2021 +0700 Merge branch 'master' into refactor/styles commit ec12eb2 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Tue Nov 30 16:55:06 2021 +0700 test: write tests for rust functions commit f044269 Author: Stanley Owen <69080584+stanleyowen@users.noreply.github.com> Date: Tue Nov 30 16:20:26 2021 +0700 fix: use `box-shadow` instead of `border` to avoid additional width for selected files commit 216e0eb Author: Stanley Owen <69080584+stanleyowen@users.noreply.github.com> Date: Tue Nov 30 16:18:19 2021 +0700 feat: add soft edges for sidebar commit 392f758 Author: Stanley Owen <69080584+stanleyowen@users.noreply.github.com> Date: Tue Nov 30 15:56:09 2021 +0700 feat: improve hover effect for light theme commit 7ddf245 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Mon Nov 29 21:40:30 2021 +0700 docs: documenting rust functions commit 943f56d Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Mon Nov 29 19:59:56 2021 +0700 fix: repetitive confirm dialog when permanently deleting multiple files commit c1f3877 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Mon Nov 29 17:21:38 2021 +0700 refactor: developing theme extension structure commit e98c1dd Merge: 3748932 73a856a Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Nov 28 20:10:44 2021 +0700 Merge branch 'master' into feat/extensions commit 3748932 Author: Justin Maximillian Kimlim <kimlimjustin@gmail.com> Date: Sun Nov 28 19:57:52 2021 +0700 feat: color theme customization development process commit 442434f Author: Stanley Owen <69080584+stanleyowen@users.noreply.github.com> Date: Tue Nov 23 18:03:53 2021 +0700 feat: improve hover and active effects across themes commit e3500b0 Author: Stanley Owen <69080584+stanleyowen@users.noreply.github.com> Date: Sat Nov 20 21:59:02 2021 +0700 feat: add `active` attribute for components in home section commit cd843bb Author: Stanley Owen <69080584+stanleyowen@users.noreply.github.com> Date: Sat Nov 20 21:50:07 2021 +0700 feat: improve ui for selected files
Motivation
The current sort method is by brutally sorting it alphabetically, this PR intended to make it more humanly by adding feature to automatically sort the file by parsing locale information from the file name and sort it using
localeCompare
.Changes
Intl.Collator
to compare file namesRelated
Requested on #196
Additional Comments
@uahnbu Could you please review this PR? does this PR works well as you expected?