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