From 21ac88e442a73c67844bae21a4c61ce879fec1a1 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! --- .../components/coursebook/Coursebook.vue | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue index 286481188..26ed6afc7 100644 --- a/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue +++ b/aleksis/apps/alsijil/frontend/components/coursebook/Coursebook.vue @@ -105,6 +105,8 @@ export default { knownDates: {}, docsByDay: {}, lastQuery: null, + dateStart: "", + dateEnd: "", // Placeholder values while query isn't completed yet groups: [], courses: [], @@ -116,13 +118,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, }; }, @@ -154,6 +155,10 @@ export default { }, hash: this.$route.hash, }); + // computed should not have side effects + // but this was actually done before filters was refactored into + // its own component + this.resetDate(); } }, }, @@ -172,7 +177,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(); }, // => {dt: [dt doc ...] ...} groupDocsByDay(docs) { @@ -326,7 +332,8 @@ export default { // scroll }, }, - mounted() { + created() { + this.resetDate(); window.addEventListener('scroll', this.debounce(this.setCurrentDay, 300)); }, }; -- GitLab