Skip to content

Commit

Permalink
Fix accounts sorting - Closes #347
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubka committed Jul 30, 2024
1 parent 4e463a7 commit 5d3a1be
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
4 changes: 4 additions & 0 deletions resources/js/composables/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ export function useDisplayablePassword(pwd, reveal = false) {
}

return user.preferences.showOtpAsDot && !reveal ? pwd.replace(/[0-9]/g, '●') : pwd
}

export function startsWithUppercase(str) {
return str.substr(0, 1).match(/[A-Z\u00C0-\u00DC]/);
}
29 changes: 21 additions & 8 deletions resources/js/stores/twofaccounts.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineStore } from 'pinia'
import { startsWithUppercase } from '@/composables/helpers'
import { useUserStore } from '@/stores/user'
import { useNotifyStore } from '@/stores/notify'
import twofaccountService from '@/services/twofaccountService'
Expand Down Expand Up @@ -181,21 +182,33 @@ export const useTwofaccounts = defineStore({
* Sorts accounts ascending
*/
sortAsc() {
if (useUserStore().preferences.sortCaseSensitive) {
this.items.sort((a, b) => a.service > b.service ? 1 : -1)
}
else this.items.sort((a, b) => a.service.toLowerCase() > b.service.toLowerCase() ? 1 : -1)
this.items.sort(function(a, b) {
if (useUserStore().preferences.sortCaseSensitive) {
if (startsWithUppercase(a.service) && !startsWithUppercase(b.service)) {
return -1;
} else if (startsWithUppercase(b.service) && !startsWithUppercase(a.service)) {
return 1;
}
}
return a.service.localeCompare(b.service, useUserStore().preferences.lang)
});
this.saveOrder()
},

/**
* Sorts accounts descending
*/
sortDesc() {
if (useUserStore().preferences.sortCaseSensitive) {
this.items.sort((a, b) => a.service < b.service ? 1 : -1)
}
else this.items.sort((a, b) => a.service.toLowerCase() < b.service.toLowerCase() ? 1 : -1)
this.items.sort(function(a, b) {
if (useUserStore().preferences.sortCaseSensitive) {
if (startsWithUppercase(a.service) && !startsWithUppercase(b.service)) {
return 1;
} else if (startsWithUppercase(b.service) && !startsWithUppercase(a.service)) {
return -1;
}
}
return b.service.localeCompare(a.service, useUserStore().preferences.lang)
});
this.saveOrder()
},

Expand Down

0 comments on commit 5d3a1be

Please sign in to comment.