From e2edbb707c113dc55e7896145d4931af9a736d42 Mon Sep 17 00:00:00 2001
From: Alejandro Akbal <37181533+VoidlessSeven7@users.noreply.github.com>
Date: Sun, 28 Feb 2021 14:46:21 +0100
Subject: [PATCH] feat: reimagine infinite loading
---
.../pages/posts/navigation/page/Controls.vue | 58 ++++++++++++++-----
1 file changed, 45 insertions(+), 13 deletions(-)
diff --git a/components/pages/posts/navigation/page/Controls.vue b/components/pages/posts/navigation/page/Controls.vue
index 5a6b135b..9683554a 100644
--- a/components/pages/posts/navigation/page/Controls.vue
+++ b/components/pages/posts/navigation/page/Controls.vue
@@ -45,13 +45,19 @@
-
-
Loading more posts...
+
+
+ Stay here to load more posts...
+
@@ -112,15 +118,41 @@ export default {
await this.pidManager({ operation: 'set', value: specificPage })
},
- InfiniteLoadHandler: throttle(async function () {
- console.debug('Loading more posts')
+ InfiniteLoadHandler(entries, observer) {
+ const elementAttribute = 'data-is-visible'
+ const timeoutDelay = 3000
- await this.pidManager({ operation: 'add' })
- }, 5000),
- },
-}
+ // console.log({ entries, observer })
+
+ entries.forEach((entry) => {
+ if (!entry.isIntersecting || entry.intersectionRatio <= 0) {
+ //
+ if (entry.target.getAttribute(elementAttribute)) {
+ // console.debug('Removed attribute from element.')
+ entry.target.removeAttribute(elementAttribute)
+ }
+ // console.debug('Element is not visible.')
+ return
+ }
+ entry.target.setAttribute(elementAttribute, true)
+
+ setTimeout(async () => {
+ const isVisible = entry.target.getAttribute(elementAttribute)
+
+ if (!isVisible) {
+ // console.debug('Timeout: Element does not have attribute.')
+ return
+ }
+
+ console.debug('Loading more posts...')
+
+ await this.pidManager({ operation: 'add' })
+ }, timeoutDelay)
+ })
+ },
+ },
}