From 1653386da964125f4da4e41c78866744f40c396a Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 22 Apr 2023 14:30:31 +0200 Subject: [PATCH] Properly sort bots for dashboard --- src/shared/userService.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/shared/userService.ts b/src/shared/userService.ts index 04957983..03899612 100644 --- a/src/shared/userService.ts +++ b/src/shared/userService.ts @@ -99,14 +99,17 @@ export class UserService { public static getAvailableBots(): BotDescriptors { const allInfo = UserService.getAllLoginInfos(); const response: BotDescriptors = {}; - Object.entries(allInfo).forEach(([k, v], idx) => { - response[k] = { - botId: k, - botName: v.botName, - botUrl: v.apiUrl, - sortId: v.sortId ?? idx, - }; - }); + Object.keys(allInfo) + .sort((a, b) => (allInfo[a].sortId ?? 0) - (allInfo[b].sortId ?? 0)) + .forEach((k, idx) => { + response[k] = { + botId: k, + botName: allInfo[k].botName, + botUrl: allInfo[k].apiUrl, + sortId: allInfo[k].sortId ?? idx, + }; + }); + return response; }