ensure nulls arent passed to sort

This commit is contained in:
Beebles
2024-09-13 18:46:49 -06:00
parent ab3b69ffed
commit 2384f6c40e

View File

@@ -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();
});
})
);
});
}