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

Make current day detection more robust.

This version does not rely on internal state anymore.
parent 589ed5af
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"
......@@ -18,7 +18,12 @@
<template #default="{ items }">
<v-list-item
v-for="{ date, docs, first, last } in groupDocsByDay(items)"
v-intersect="onIntersect"
v-intersect="{
handler: onIntersect,
options: {
threshold: [0, 1]
}
}"
:data-date="date.toISODate()"
:data-first="first"
:data-last="last"
......@@ -174,7 +179,11 @@ export default {
if (!this.$route.hash) {
console.log('Set default date');
this.$router.replace({ hash: DateTime.now().toISODate() })
}
}
// if (date) {
// this.$router.replace({ hash: date })
// }
const date = DateTime.fromISO(this.$route.hash.substring(1));
// Reset visible
this.visible = [];
......@@ -218,7 +227,7 @@ export default {
console.log('fetchMoreResult', fetchMoreResult);
return { items: previousResult.items.concat(fetchMoreResult.items) };
}
});
});
},
setDate(date) {
this.$router.replace({ hash: date })
......@@ -226,18 +235,11 @@ export default {
onIntersect(entries, observer) {
const entry = entries[0];
if (entry.isIntersecting) {
// coming
console.log('intersect', this.visible);
// track visible
if (this.visible[0] > entry.target.dataset.date || this.visible.length === 0) {
// coming is new first (top) date
this.visible.unshift(entry.target.dataset.date);
this.setDate(this.visible[0]);
} else if (this.visible[this.visible.length -1] < entry.target.dataset.date) {
// coming is new last (bottom) date
this.visible.push(entry.target.dataset.date);
}
if (entry.boundingClientRect.top <= 0) {
console.log('@', entry.target.dataset.date);
this.setDate(entry.target.dataset.date);
}
// load more
if (entry.target.dataset.first) {
......@@ -253,13 +255,6 @@ export default {
this.fetchMore(date.plus({ days: 1 }).toISODate(),
date.plus({ days: 5 }).toISODate());
}
} else if (this.visible[0] === entry.target.dataset.date) {
// first (top) visible date is going
this.visible.shift()
this.setDate(this.visible[0]);
} else if (this.visible[this.visible.length - 1] === entry.target.dataset.date) {
// last (bottom) visible date is going
this.visible.pop()
}
},
},
......
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