From bedd1a4617a958078fda03093dd7f3defc2816b2 Mon Sep 17 00:00:00 2001 From: Arjun Patel Date: Sun, 16 Jan 2022 14:41:09 -0800 Subject: [PATCH] fixing sort --- helpers/userHelper.tsx | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/helpers/userHelper.tsx b/helpers/userHelper.tsx index 7f2ad8e..549476f 100644 --- a/helpers/userHelper.tsx +++ b/helpers/userHelper.tsx @@ -1,17 +1,18 @@ import { User, UserStatus } from "../models/user"; -export function compareStatus(usera: User, userb: User) { - if (usera.userStatus == UserStatus.online) { - return -2; +function getStatusValue(status: UserStatus) { + switch (status) { + case UserStatus.online: + return 10; + case UserStatus.busy: + return 5; + case UserStatus.offline: + return 0; + default: + return -5; } - - if (usera.userStatus == UserStatus.busy) { - return -1; - } - - if (usera.userStatus == UserStatus.offline) { - return 0; - } - - return 2; +} + +export function compareStatus(usera: User, userb: User) { + return getStatusValue(userb.userStatus) - getStatusValue(usera.userStatus); }