Skip to content

Commit

Permalink
ensure nulls arent passed to sort
Browse files Browse the repository at this point in the history
  • Loading branch information
beebls committed Sep 14, 2024
1 parent ab3b69f commit 2384f6c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions frontend/src/components/AnnouncementsDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ export function AnnouncementsDisplay() {
setAnnouncements((oldAnnouncements) => {
const newArr = [...oldAnnouncements, ...newAnnouncements];
const setOfIds = new Set(newArr.map((a) => a.id));
return Array.from(setOfIds)
.map((id) => newArr.find((a) => a.id === id)!)
.sort((a, b) => {
return (
(
Array.from(setOfIds)
.map((id) => newArr.find((a) => a.id === id))
// Typescript doesn't type filter(Boolean) correctly, so I have to assert this
.filter(Boolean) as Announcement[]
).sort((a, b) => {
return new Date(b.created).getTime() - new Date(a.created).getTime();
});
})
);
});
}

Expand Down

0 comments on commit 2384f6c

Please sign in to comment.