Skip to content
Snippets Groups Projects
Commit 21ac88e4 authored by permcu's avatar permcu
Browse files

Make computed gqlQueryArgs side-effect free again

Was loading while scrolling before!
parent bb903b61
No related branches found
No related tags found
2 merge requests!355Implement infinite scrolling and by date navigation for coursebook,!350Resolve "Add simple course book list"
...@@ -105,6 +105,8 @@ export default { ...@@ -105,6 +105,8 @@ export default {
knownDates: {}, knownDates: {},
docsByDay: {}, docsByDay: {},
lastQuery: null, lastQuery: null,
dateStart: "",
dateEnd: "",
// Placeholder values while query isn't completed yet // Placeholder values while query isn't completed yet
groups: [], groups: [],
courses: [], courses: [],
...@@ -116,13 +118,12 @@ export default { ...@@ -116,13 +118,12 @@ export default {
// Resets date range. // Resets date range.
gqlQueryArgs() { gqlQueryArgs() {
console.log('computing gqlQueryArgs'); console.log('computing gqlQueryArgs');
const dateRange = this.resetDate();
return { return {
own: this.filterType === "all" ? false : true, own: this.filterType === "all" ? false : true,
objId: this.objId ? Number(this.objId) : undefined, objId: this.objId ? Number(this.objId) : undefined,
objType: this.objType?.toUpperCase(), objType: this.objType?.toUpperCase(),
dateStart: dateRange[0].toISODate(), dateStart: this.dateStart,
dateEnd: dateRange[1].toISODate(), dateEnd: this.dateEnd,
incomplete: !!this.incomplete, incomplete: !!this.incomplete,
}; };
}, },
...@@ -154,6 +155,10 @@ export default { ...@@ -154,6 +155,10 @@ export default {
}, },
hash: this.$route.hash, 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 { ...@@ -172,7 +177,8 @@ export default {
dateRange.forEach((ts) => this.knownDates[ts] = true); dateRange.forEach((ts) => this.knownDates[ts] = true);
const lastIdx = dateRange.length - 1; const lastIdx = dateRange.length - 1;
// Returning a dateRange each around first & last date for the initial query // 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 ...] ...} // => {dt: [dt doc ...] ...}
groupDocsByDay(docs) { groupDocsByDay(docs) {
...@@ -326,7 +332,8 @@ export default { ...@@ -326,7 +332,8 @@ export default {
// scroll // scroll
}, },
}, },
mounted() { created() {
this.resetDate();
window.addEventListener('scroll', this.debounce(this.setCurrentDay, 300)); window.addEventListener('scroll', this.debounce(this.setCurrentDay, 300));
}, },
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment