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

Make current day detection more robust.

This version does not rely on internal state anymore.
parent 7a0d7d29
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,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"
......@@ -208,7 +213,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 = [];
......@@ -267,7 +276,7 @@ export default {
console.log('fetchMoreResult', fetchMoreResult);
return { items: previousResult.items.concat(fetchMoreResult.items) };
}
});
});
},
setDate(date) {
this.$router.replace({ hash: date })
......@@ -275,18 +284,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) {
......@@ -302,13 +304,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