From ca40d30ca7dd1ab7d0f473b37759b98c9b03eb20 Mon Sep 17 00:00:00 2001 From: George Kaye Date: Sun, 4 Feb 2024 22:43:44 +0000 Subject: [PATCH] [fix] Sort things after updating --- client/src/app/page.tsx | 6 ++++-- client/src/app/structs.ts | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/client/src/app/page.tsx b/client/src/app/page.tsx index e6b24b6..afe431b 100644 --- a/client/src/app/page.tsx +++ b/client/src/app/page.tsx @@ -55,7 +55,8 @@ const Home = () => { data.breaks, newBreaks, breaksToRemove, - (b1, b2) => b1.id === b2.id + (b1, b2) => b1.id === b2.id, + (b1, b2) => b1.datetime.getTime() - b2.datetime.getTime() ) setData({ breaks: updatedBreaks, claims: data.claims }) return updatedBreaks @@ -65,7 +66,8 @@ const Home = () => { data.claims, newClaims, claimsToRemove, - (c1, c2) => c1.id === c2.id + (c1, c2) => c1.id === c2.id, + (c1, c2) => c1.date.getTime() - c2.date.getTime() ) setClaims(updatedClaims) return updatedClaims diff --git a/client/src/app/structs.ts b/client/src/app/structs.ts index c27678c..b9e881e 100644 --- a/client/src/app/structs.ts +++ b/client/src/app/structs.ts @@ -42,7 +42,8 @@ export const replaceItems = ( oldItems: T[], itemsToAdd: T[], itemsToRemove: T[], - eqCheck: (t1: T, t2: T) => boolean + eqCheck: (t1: T, t2: T) => boolean, + sortFn: (t1: T, t2: T) => number ) => oldItems .filter( @@ -51,6 +52,7 @@ export const replaceItems = ( !itemsToRemove.find((remItem) => eqCheck(oldItem, remItem)) ) .concat(itemsToAdd) + .sort(sortFn) export const getDateString = (datetime: Date) => { let weekday = datetime.toLocaleDateString("en-GB", {