From e2d3a338f353ebcc46511b1e71d7d9f6992626b8 Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Fri, 22 Mar 2024 12:56:19 +0100
Subject: [PATCH] Make computed gqlQueryArgs side-effect free again

Was loading while scrolling before!
---
 .../frontend/components/coursebook/Coursebook.vue  | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
index c67178e82..8f07110e1 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue
@@ -148,6 +148,8 @@ export default {
       knownDates: {},
       docsByDay: {},
       lastQuery: null,
+      dateStart: "",
+      dateEnd: "",
       // Placeholder values while query isn't completed yet
       groups: [],
       courses: [],
@@ -167,13 +169,12 @@ export default {
     //            Resets date range.
     gqlQueryArgs() {
       console.log('computing gqlQueryArgs');
-      const dateRange = this.resetDate();
       return {
         own: this.filterType === "all" ? false : true,
         objId: this.objId ? Number(this.objId) : undefined,
         objType: this.objType?.toUpperCase(),
-        dateStart: dateRange[0].toISODate(),
-        dateEnd: dateRange[1].toISODate(),
+        dateStart: this.dateStart,
+        dateEnd: this.dateEnd,
         incomplete: !!this.incomplete,
       };
     },
@@ -211,7 +212,8 @@ export default {
       dateRange.forEach((ts) => this.knownDates[ts] = true);
       const lastIdx = dateRange.length - 1;
       // Returning a dateRange each around first & last date for the initial query
-      return [this.dateRange(dateRange[0])[0], this.dateRange(dateRange[lastIdx])[lastIdx]];
+      this.dateStart = this.dateRange(dateRange[0])[0].toISODate();
+      this.dateEnd = this.dateRange(dateRange[lastIdx])[lastIdx].toISODate();
     },
     changeSelection(selection) {
       this.$router.push({
@@ -225,6 +227,7 @@ export default {
         },
         hash: this.$route.hash,
       });
+      this.resetDate();
     },
     // => {dt: [dt doc ...] ...}
     groupDocsByDay(docs) {
@@ -378,7 +381,8 @@ export default {
       // scroll
     },
   },
-  mounted() {
+  created() {
+    this.resetDate();
     window.addEventListener('scroll', this.debounce(this.setCurrentDay, 300));
   },
 };
-- 
GitLab