From bc52df6049d1aec1086b9cce521696f0780f335a Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Wed, 27 Mar 2024 17:29:29 +0100
Subject: [PATCH] Update date logic

---
 .../components/coursebook/Coursebook.vue      | 25 ++++++-------------
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
index f3ac4bbca..f8aaec4ca 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
@@ -148,10 +148,8 @@ export default {
   data() {
     return {
       gqlQuery: documentationsForCoursebook,
-      currentDate: "",
-      visible: [],
-      knownDates: {},
       lastQuery: null,
+      visible: [],
       dateStart: "",
       dateEnd: "",
       // Placeholder values while query isn't completed yet
@@ -211,15 +209,11 @@ export default {
         console.log('Set default date');
         this.$router.replace({ hash: DateTime.now().toISODate() })
       }
-      // Resetting known dates to dateRange around current date
-      this.knownDates = {};
-      this.currentDate = this.$route.hash.substring(1);
-      const dateRange = this.dateRange(DateTime.fromISO(this.$route.hash.substring(1)));
-      dateRange.forEach((ts) => this.knownDates[ts] = true);
-      const lastIdx = dateRange.length - 1;
-      // Returning a dateRange each around first & last date for the initial query
-      this.dateStart = this.dateRange(dateRange[0])[0].toISODate();
-      this.dateEnd = this.dateRange(dateRange[lastIdx])[lastIdx].toISODate();
+      const date = DateTime.fromISO(this.$route.hash.substring(1));
+      // Reset visible
+      this.visible = [];
+      this.dateStart = date.minus({ days: 3 }).toISODate();
+      this.dateEnd = date.plus({ days: 4 }).toISODate();
     },
     changeSelection(selection) {
       this.$router.push({
@@ -234,6 +228,7 @@ export default {
         hash: this.$route.hash,
       });
       this.resetDate();
+      // might skip query until both set = atomic
     },
     groupDocsByDay(docs) {
       // => {dt: [dt doc ...] ...}
@@ -258,12 +253,6 @@ export default {
         });
       // sorting is necessary since backend can send docs unordered
     },
-    dateRange(date) {
-      return Interval
-        .fromDateTimes(date.minus({ days: 3 }), date.plus({ days: 4 }))
-        .splitBy({ days: 1 })
-        .map((ts) => ts.start);
-    },
     // docsByDay: {dt: [dt doc ...] ...}
     assureDate(date) {
       if (!this.knownDates[date]) {
-- 
GitLab