From 0b20fd773088c6aa6fe7ad1274291b3e4ae85ad6 Mon Sep 17 00:00:00 2001 From: Jake Fulmine Date: Sat, 21 Jan 2023 19:55:50 +0100 Subject: [PATCH] fix(dashboard): improve slow search when sorting by a date field --- dashboard/src/components/list/functions.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/dashboard/src/components/list/functions.ts b/dashboard/src/components/list/functions.ts index 67f4a6f9..314d2b7a 100644 --- a/dashboard/src/components/list/functions.ts +++ b/dashboard/src/components/list/functions.ts @@ -1,6 +1,5 @@ import type { Group, Member } from '../../api/types'; import type { ListOptions, PageOptions } from './types'; -import moment from 'moment'; export function filterList(list: T[], options: ListOptions, type?: string): T[] { let searchedList = search(list, options); @@ -105,11 +104,10 @@ function sort(list: T[], options: ListOptions): T[] { if (aa === null) return 1; if (bb === null) return -1; - let aBirthday = moment(aa.slice(5, aa.length), "MM-DD", true); - let bBirthday = moment(bb.slice(5, bb.length), "MM-DD", true); + let aBirthday = aa.slice(5, aa.length); + let bBirthday = bb.slice(5, bb.length); - if (aBirthday.isAfter(bBirthday)) return 1; - if (aBirthday.isBefore(bBirthday)) return -1; + return aBirthday.localeCompare(bBirthday); }); } else if (options.sort === 'created') { newList = [...list].sort((a, b) => { @@ -121,11 +119,7 @@ function sort(list: T[], options: ListOptions): T[] { if (aa === null) return 1; if (bb === null) return -1; - let aCreated = moment(aa); - let bCreated = moment(bb); - - if (aCreated.isAfter(bCreated)) return 1; - if (aCreated.isBefore(bCreated)) return -1; + return aa.localeCompare(bb); }); } return newList;