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

Precompute first & last for intersectHandler

parent 7cda6e6f
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"
......@@ -19,9 +19,9 @@
<template #default="{ items }">
<coursebook-loader />
<coursebook-day
v-for="{ date, docs, idx, lastIdx } in groupDocsByDay(items)"
v-for="{ date, docs, first, last } in groupDocsByDay(items)"
v-intersect="{
handler: intersectHandler(date, idx, lastIdx),
handler: intersectHandler(date, first, last),
options: {
rootMargin: '-165px 0px 0px 0px',
threshold: [0, 1],
......@@ -200,8 +200,9 @@ export default {
.sort()
.map((key, idx, {length}) => {
const day = docsByDay[key];
day.idx = idx;
day.lastIdx = length - 1;
day.first = idx === 0;
const lastIdx = length - 1;
day.last = idx === lastIdx;
return day;
});
},
......@@ -241,7 +242,7 @@ export default {
}
});
},
intersectHandler(date, idx, lastIdx) {
intersectHandler(date, first, last) {
let once = true;
return (entries) => {
const entry = entries[0];
......@@ -253,7 +254,7 @@ export default {
this.setDate(date.toISODate());
}
if (once && this.ready && idx === 0) {
if (once && this.ready && first) {
console.log('load up', date.toISODate());
this.ready = false;
this.fetchMore(date.minus({ days: 5 }).toISODate(),
......@@ -263,7 +264,7 @@ export default {
document.documentElement.scrollTop);
});
once = false;
} else if (once && this.ready && idx === lastIdx) {
} else if (once && this.ready && last) {
console.log('load down', date.toISODate());
this.ready = false;
this.fetchMore(date.plus({ days: 1 }).toISODate(),
......
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