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

Introduce knownDates and dateRanges

parent 915e6d61
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"
...@@ -102,29 +102,27 @@ export default { ...@@ -102,29 +102,27 @@ export default {
data() { data() {
return { return {
gqlQuery: documentationsForCoursebook, gqlQuery: documentationsForCoursebook,
knownDates: {},
docsByDay: {}, docsByDay: {},
lastQuery: null, lastQuery: null,
// Placeholder values while query isn't completed yet // Placeholder values while query isn't completed yet
groups: [], groups: [],
courses: [], courses: [],
dateStart: null,
dateEnd: null,
incomplete: false, incomplete: false,
}; };
}, },
computed: { computed: {
// TODO: Query should wait until dateStart is set! // Assertion: Should only fire on page load or selection change.
// = wait for mounted // 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: this.dateStart ?? this.date, dateStart: dateRange[0].toISODate(),
dateEnd: dateEnd: dateRange[1].toISODate(),
this.dateEnd ??
DateTime.fromISO(this.date).plus({ weeks: 1 }).toISODate(),
incomplete: !!this.incomplete, incomplete: !!this.incomplete,
}; };
}, },
...@@ -161,6 +159,21 @@ export default { ...@@ -161,6 +159,21 @@ export default {
}, },
}, },
methods: { methods: {
resetDate() {
// Assure current date
console.log('Resetting date range', this.$route.hash);
if (!this.$route.hash) {
console.log('Set default date');
this.$router.replace({ hash: DateTime.now().toISODate() })
}
// Resetting known dates to dateRange around current date
this.knownDates = {};
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
return [this.dateRange(dateRange[0])[0], this.dateRange(dateRange[lastIdx])[lastIdx]];
},
// => {dt: [dt doc ...] ...} // => {dt: [dt doc ...] ...}
groupDocsByDay(docs) { groupDocsByDay(docs) {
return docs.reduce((byDay, doc) => { return docs.reduce((byDay, doc) => {
...@@ -276,10 +289,9 @@ export default { ...@@ -276,10 +289,9 @@ export default {
.splitBy({ days: 1 }) .splitBy({ days: 1 })
.map((ts) => ts.start); .map((ts) => ts.start);
}, },
// TODO: Improve Add empty but already queried days to docsByDay -> do not query them again
// docsByDay: {dt: [dt doc ...] ...} // docsByDay: {dt: [dt doc ...] ...}
assureDate(date) { assureDate(date) {
if (!this.knownDate[date]) { if (!this.knownDates[date]) {
// find missing & fetch missing range // find missing & fetch missing range
// date +- 5 days ? // date +- 5 days ?
const dateRange = Interval const dateRange = Interval
...@@ -308,14 +320,6 @@ export default { ...@@ -308,14 +320,6 @@ export default {
}, },
}, },
mounted() { mounted() {
// assure date hash
console.log('mounted with hash', this.$route.hash);
if (!this.$route.hash) {
console.log('initialized hash');
this.$router.replace({ hash: DateTime.now().toISODate() })
}
this.dateStart = this.$route.hash.substring(1);
this.dateEnd = DateTime.fromISO(this.dateStart).plus({ weeks: 1 }).toISODate()
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