feat: Add infinite loader, option for increasing page size (#8525)
Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com>
This commit is contained in:
34
app/javascript/dashboard/components/IntersectionObserver.vue
Normal file
34
app/javascript/dashboard/components/IntersectionObserver.vue
Normal file
@@ -0,0 +1,34 @@
|
||||
<template>
|
||||
<div ref="observedElement" class="h-6 w-full" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
props: {
|
||||
options: {
|
||||
type: Object,
|
||||
default: () => ({ root: document, rootMargin: '100px 0 100px 0)' }),
|
||||
},
|
||||
},
|
||||
mounted() {
|
||||
this.intersectionObserver = null;
|
||||
this.registerInfiniteLoader();
|
||||
},
|
||||
beforeDestroy() {
|
||||
this.unobserveInfiniteLoadObserver();
|
||||
},
|
||||
methods: {
|
||||
registerInfiniteLoader() {
|
||||
this.intersectionObserver = new IntersectionObserver(entries => {
|
||||
if (entries && entries[0].isIntersecting) {
|
||||
this.$emit('observed');
|
||||
}
|
||||
}, this.options);
|
||||
this.intersectionObserver.observe(this.$refs.observedElement);
|
||||
},
|
||||
unobserveInfiniteLoadObserver() {
|
||||
this.intersectionObserver.unobserve(this.$refs.observedElement);
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
Reference in New Issue
Block a user