viewer: refactor preloading
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/900/head
parent
e13e9cb37b
commit
18b8a5404f
|
@ -397,10 +397,6 @@ export default defineComponent({
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
fetchDay(dayId: number) {
|
|
||||||
utils.bus.emit('memories:timeline:fetch-day', dayId);
|
|
||||||
},
|
|
||||||
|
|
||||||
updateLoading(delta: number) {
|
updateLoading(delta: number) {
|
||||||
this.loading += delta;
|
this.loading += delta;
|
||||||
},
|
},
|
||||||
|
@ -722,23 +718,21 @@ export default defineComponent({
|
||||||
const photo = this.list[idx];
|
const photo = this.list[idx];
|
||||||
|
|
||||||
// Something went really wrong
|
// Something went really wrong
|
||||||
if (!photo) {
|
if (!photo) return {};
|
||||||
return {};
|
|
||||||
}
|
// Get index of current day in dayIds lisst
|
||||||
|
const dayIdx = utils.binarySearch(this.dayIds, photo.dayid);
|
||||||
|
|
||||||
// Preload next and previous 3 days
|
// Preload next and previous 3 days
|
||||||
const dayIdx = utils.binarySearch(this.dayIds, photo.dayid);
|
for (let idx = dayIdx - 3; idx <= dayIdx + 3; idx++) {
|
||||||
const preload = (idx: number) => {
|
if (idx < 0 || idx >= this.dayIds.length || idx === dayIdx) continue;
|
||||||
if (idx > 0 && idx < this.dayIds.length && !this.days.get(this.dayIds[idx])?.detail) {
|
|
||||||
this.fetchDay(this.dayIds[idx]);
|
const day = this.days.get(this.dayIds[idx]);
|
||||||
|
if (day && !day?.detail) {
|
||||||
|
// duplicate requests are skipped by Timeline
|
||||||
|
utils.bus.emit('memories:timeline:fetch-day', day.dayid);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
preload(dayIdx - 1);
|
|
||||||
preload(dayIdx - 2);
|
|
||||||
preload(dayIdx - 3);
|
|
||||||
preload(dayIdx + 1);
|
|
||||||
preload(dayIdx + 2);
|
|
||||||
preload(dayIdx + 3);
|
|
||||||
|
|
||||||
// Get thumb image
|
// Get thumb image
|
||||||
const thumbSrc: string =
|
const thumbSrc: string =
|
||||||
|
@ -764,9 +758,7 @@ export default defineComponent({
|
||||||
if (thumb && this.fullyOpened) {
|
if (thumb && this.fullyOpened) {
|
||||||
const rect = thumb.getBoundingClientRect();
|
const rect = thumb.getBoundingClientRect();
|
||||||
if (rect.bottom < 50 || rect.top > _m.window.innerHeight - 50) {
|
if (rect.bottom < 50 || rect.top > _m.window.innerHeight - 50) {
|
||||||
thumb.scrollIntoView({
|
thumb.scrollIntoView({ block: 'center' });
|
||||||
block: 'center',
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue