Skip to content

Commit

Permalink
Merge pull request #88 from georgejkaye/sort-updated-data
Browse files Browse the repository at this point in the history
[fix] Sort things after updating
  • Loading branch information
georgejkaye authored Feb 4, 2024
2 parents b8462e1 + ca40d30 commit ea96ead
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions client/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion client/src/app/structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const replaceItems = <T>(
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(
Expand All @@ -51,6 +52,7 @@ export const replaceItems = <T>(
!itemsToRemove.find((remItem) => eqCheck(oldItem, remItem))
)
.concat(itemsToAdd)
.sort(sortFn)

export const getDateString = (datetime: Date) => {
let weekday = datetime.toLocaleDateString("en-GB", {
Expand Down

0 comments on commit ea96ead

Please sign in to comment.