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

Move to internal currentDate state and update hash fragment on idle

Updating the hash fragment causes a small delay while scrolling.
=> Update only after user finished scrolling.
Uses requestIdleCallback
which is not ready for prime time in Safari. But should work elsewhere.
parent bbf918c7
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"
Pipeline #181047 failed
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
<coursebook-loader /> <coursebook-loader />
<date-select-footer <date-select-footer
:value="$route.hash.substring(1)" :value="currentDate"
@input="gotoDate" @input="gotoDate"
@prev="gotoPrev" @prev="gotoPrev"
@next="gotoNext" @next="gotoNext"
...@@ -114,6 +114,8 @@ export default { ...@@ -114,6 +114,8 @@ export default {
incomplete: false, incomplete: false,
ready: false, ready: false,
initDate: false, initDate: false,
currentDate: "",
hashUpdater: false,
}; };
}, },
computed: { computed: {
...@@ -171,12 +173,13 @@ export default { ...@@ -171,12 +173,13 @@ export default {
resetDate() { resetDate() {
// Assure current date // Assure current date
console.log('Resetting date range', this.$route.hash); console.log('Resetting date range', this.$route.hash);
if (!this.$route.hash) { this.currentDate = this.$route.hash?.substring(1);
if (!this.currentDate) {
console.log('Set default date'); console.log('Set default date');
this.setDate(DateTime.now().toISODate()); this.setDate(DateTime.now().toISODate());
} }
const date = DateTime.fromISO(this.$route.hash.substring(1)); const date = DateTime.fromISO(this.currentDate);
this.initDate = date; this.initDate = date;
this.dateStart = date.minus({ days: 3 }).toISODate(); this.dateStart = date.minus({ days: 3 }).toISODate();
this.dateEnd = date.plus({ days: 4 }).toISODate(); this.dateEnd = date.plus({ days: 4 }).toISODate();
...@@ -224,8 +227,14 @@ export default { ...@@ -224,8 +227,14 @@ export default {
}); });
}, },
setDate(date) { setDate(date) {
if (!(this.$route.hash.substring(1) === date)) { this.currentDate = date;
this.$router.replace({ hash: date }) if (!this.hashUpdater) {
this.hashUpdater = window.requestIdleCallback(() => {
if (!(this.$route.hash.substring(1) === this.currentDate)) {
this.$router.replace({ hash: this.currentDate })
}
this.hashUpdater = false;
});
} }
}, },
fixScrollPos(height, top) { fixScrollPos(height, top) {
...@@ -294,20 +303,18 @@ export default { ...@@ -294,20 +303,18 @@ export default {
}, },
// TODO: Disable navigation while loading! // TODO: Disable navigation while loading!
gotoPrev() { gotoPrev() {
const current = this.$route.hash.substring(1);
const pref = this.$refs.days const pref = this.$refs.days
.map((day) => day.date.toISODate()) .map((day) => day.date.toISODate())
.sort() .sort()
.reverse() .reverse()
.find((date) => date < current); .find((date) => date < this.currentDate);
this.gotoDate(pref); this.gotoDate(pref);
}, },
gotoNext() { gotoNext() {
const current = this.$route.hash.substring(1);
const next = this.$refs.days const next = this.$refs.days
.map((day) => day.date.toISODate()) .map((day) => day.date.toISODate())
.sort() .sort()
.find((date) => date > current); .find((date) => date > this.currentDate);
this.gotoDate(next); this.gotoDate(next);
}, },
}, },
......
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