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 @@ ...@@ -59,7 +59,12 @@
<template #default="{ items }"> <template #default="{ items }">
<v-list-item <v-list-item
v-for="{ date, docs, first, last } in groupDocsByDay(items)" 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-date="date.toISODate()"
:data-first="first" :data-first="first"
:data-last="last" :data-last="last"
...@@ -208,7 +213,11 @@ export default { ...@@ -208,7 +213,11 @@ export default {
if (!this.$route.hash) { if (!this.$route.hash) {
console.log('Set default date'); console.log('Set default date');
this.$router.replace({ hash: DateTime.now().toISODate() }) this.$router.replace({ hash: DateTime.now().toISODate() })
} }
// if (date) {
// this.$router.replace({ hash: date })
// }
const date = DateTime.fromISO(this.$route.hash.substring(1)); const date = DateTime.fromISO(this.$route.hash.substring(1));
// Reset visible // Reset visible
this.visible = []; this.visible = [];
...@@ -267,7 +276,7 @@ export default { ...@@ -267,7 +276,7 @@ export default {
console.log('fetchMoreResult', fetchMoreResult); console.log('fetchMoreResult', fetchMoreResult);
return { items: previousResult.items.concat(fetchMoreResult.items) }; return { items: previousResult.items.concat(fetchMoreResult.items) };
} }
}); });
}, },
setDate(date) { setDate(date) {
this.$router.replace({ hash: date }) this.$router.replace({ hash: date })
...@@ -275,18 +284,11 @@ export default { ...@@ -275,18 +284,11 @@ export default {
onIntersect(entries, observer) { onIntersect(entries, observer) {
const entry = entries[0]; const entry = entries[0];
if (entry.isIntersecting) { if (entry.isIntersecting) {
// coming
console.log('intersect', this.visible);
// track visible if (entry.boundingClientRect.top <= 0) {
if (this.visible[0] > entry.target.dataset.date || this.visible.length === 0) { console.log('@', entry.target.dataset.date);
// coming is new first (top) date this.setDate(entry.target.dataset.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);
}
// load more // load more
if (entry.target.dataset.first) { if (entry.target.dataset.first) {
...@@ -302,13 +304,6 @@ export default { ...@@ -302,13 +304,6 @@ export default {
this.fetchMore(date.plus({ days: 1 }).toISODate(), this.fetchMore(date.plus({ days: 1 }).toISODate(),
date.plus({ days: 5 }).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