Fix accounts sorting - Closes #347

This commit is contained in:
Bubka 2024-07-30 10:08:28 +02:00
parent 4e463a781b
commit 5d3a1be38f
2 changed files with 25 additions and 8 deletions

View File

@ -50,3 +50,7 @@ export function useDisplayablePassword(pwd, reveal = false) {
return user.preferences.showOtpAsDot && !reveal ? pwd.replace(/[0-9]/g, '●') : pwd 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]/);
}

View File

@ -1,4 +1,5 @@
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { startsWithUppercase } from '@/composables/helpers'
import { useUserStore } from '@/stores/user' import { useUserStore } from '@/stores/user'
import { useNotifyStore } from '@/stores/notify' import { useNotifyStore } from '@/stores/notify'
import twofaccountService from '@/services/twofaccountService' import twofaccountService from '@/services/twofaccountService'
@ -181,10 +182,16 @@ export const useTwofaccounts = defineStore({
* Sorts accounts ascending * Sorts accounts ascending
*/ */
sortAsc() { sortAsc() {
if (useUserStore().preferences.sortCaseSensitive) { this.items.sort(function(a, b) {
this.items.sort((a, b) => a.service > b.service ? 1 : -1) if (useUserStore().preferences.sortCaseSensitive) {
} if (startsWithUppercase(a.service) && !startsWithUppercase(b.service)) {
else this.items.sort((a, b) => a.service.toLowerCase() > b.service.toLowerCase() ? 1 : -1) return -1;
} else if (startsWithUppercase(b.service) && !startsWithUppercase(a.service)) {
return 1;
}
}
return a.service.localeCompare(b.service, useUserStore().preferences.lang)
});
this.saveOrder() this.saveOrder()
}, },
@ -192,10 +199,16 @@ export const useTwofaccounts = defineStore({
* Sorts accounts descending * Sorts accounts descending
*/ */
sortDesc() { sortDesc() {
if (useUserStore().preferences.sortCaseSensitive) { this.items.sort(function(a, b) {
this.items.sort((a, b) => a.service < b.service ? 1 : -1) if (useUserStore().preferences.sortCaseSensitive) {
} if (startsWithUppercase(a.service) && !startsWithUppercase(b.service)) {
else this.items.sort((a, b) => a.service.toLowerCase() < b.service.toLowerCase() ? 1 : -1) return 1;
} else if (startsWithUppercase(b.service) && !startsWithUppercase(a.service)) {
return -1;
}
}
return b.service.localeCompare(a.service, useUserStore().preferences.lang)
});
this.saveOrder() this.saveOrder()
}, },