From d35cc8e8d11680418f097b6f4c68758b2c213540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Gr=C3=B6ger?= Date: Tue, 8 Oct 2024 14:30:40 +0200 Subject: [PATCH] [feat] sort names by display name mode --- api/src/stores/user.ts | 45 ++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/api/src/stores/user.ts b/api/src/stores/user.ts index 2709950..04405a6 100644 --- a/api/src/stores/user.ts +++ b/api/src/stores/user.ts @@ -1,6 +1,7 @@ import { defineStore } from 'pinia'; import { api } from '../internal'; import { isAxiosError, useMainStore } from '.'; +import { DisplayNameMode } from '@flaschengeist/users'; export function fixUser(u?: FG.User) { return !u ? u : Object.assign(u, { birthday: u.birthday ? new Date(u.birthday) : undefined }); @@ -33,16 +34,40 @@ export const useUserStore = defineStore({ getters: { users(state) { const u = state._users.filter((u) => !u.deleted); - u.sort((a, b) => { - const a_lastname = a.lastname.toLowerCase(); - const b_lastname = b.lastname.toLowerCase(); - const a_firstname = a.firstname.toLowerCase(); - const b_firstname = b.firstname.toLowerCase(); - if (a_lastname === b_lastname) { - return a_firstname < b_firstname ? -1 : 1; - } - return a_lastname < b_lastname ? -1 : 1; - }); + + switch (this.userSettings['display_name']) { + case DisplayNameMode.FIRSTNAME_LASTNAME || DisplayNameMode.FIRSTNAME: + u.sort((a, b) => { + const a_lastname = a.lastname.toLowerCase(); + const b_lastname = b.lastname.toLowerCase(); + const a_firstname = a.firstname.toLowerCase(); + const b_firstname = b.firstname.toLowerCase(); + if (a_firstname === b_firstname) { + return a_lastname < b_lastname ? -1 : 1; + } + return a_firstname < b_firstname ? -1 : 1; + }); + break; + case DisplayNameMode.DISPLAYNAME: + u.sort((a, b) => { + const a_displayname = a.display_name.toLowerCase(); + const b_displayname = b.display_name.toLowerCase(); + return a_displayname < b_displayname ? -1 : 1; + }); + break; + default: + u.sort((a, b) => { + const a_lastname = a.lastname.toLowerCase(); + const b_lastname = b.lastname.toLowerCase(); + const a_firstname = a.firstname.toLowerCase(); + const b_firstname = b.firstname.toLowerCase(); + if (a_lastname === b_lastname) { + return a_firstname < b_firstname ? -1 : 1; + } + return a_lastname < b_lastname ? -1 : 1; + }); + } + return u; }, },