From b5af65d1036af09ea65d16c62bf57e0b993a3122 Mon Sep 17 00:00:00 2001
From: Dorian Koch <doriank@fsmpi.rwth-aachen.de>
Date: Sat, 12 Oct 2024 22:52:16 +0200
Subject: [PATCH] Lecture Import: Sort by date, closes #68

---
 src/pages/internal/import.tsx | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/pages/internal/import.tsx b/src/pages/internal/import.tsx
index f25fe84..ca6b0e1 100644
--- a/src/pages/internal/import.tsx
+++ b/src/pages/internal/import.tsx
@@ -55,14 +55,23 @@ function TerminBody({
         return (event: ICalEvent) => !nCi(event);
     };
 
+    const sortEvents = (a: ICalEvent, b: ICalEvent) => {
+        if (a.startDate === undefined || b.startDate === undefined) {
+            return 0;
+        }
+        return a.startDate.toMillis() - b.startDate.toMillis();
+    };
+
     // find events that are new (place, duration and time unique)
     const new_events = imported_events.current
         .filter(notContainedIn(existingEvents))
-        .filter(removeDuplicates);
+        .filter(removeDuplicates)
+        .sort(sortEvents);
     // find existing events that are not in the imported events
     const not_imported_events = existingEvents
         .filter(notContainedIn(imported_events.current))
-        .filter(removeDuplicates);
+        .filter(removeDuplicates)
+        .sort(sortEvents);
     // events that are in both
     const full_matches = imported_events.current
         .filter(containedIn(existingEvents))
-- 
GitLab