[#414] Support paginated results on scroll in the media Collections component.

This commit is contained in:
Fabio Manganiello 2024-10-19 17:27:39 +02:00
parent d171795e7c
commit 3a9d5700ea
Signed by untrusted user: blacklight
GPG key ID: D90FBA7F76362774

View file

@ -37,6 +37,11 @@ export default {
default: () => [], default: () => [],
}, },
batchItems: {
type: Number,
default: 100,
},
parentId: { parentId: {
type: String, type: String,
}, },
@ -45,6 +50,7 @@ export default {
data() { data() {
return { return {
fallbackImageCollections: {}, fallbackImageCollections: {},
maxResultIndex: this.batchItems,
}; };
}, },
@ -74,7 +80,7 @@ export default {
} }
return a.name.localeCompare(b.name) return a.name.localeCompare(b.name)
}) }).slice(0, this.maxResultIndex)
}, },
}, },
@ -82,6 +88,26 @@ export default {
onImageError(collection) { onImageError(collection) {
this.fallbackImageCollections[collection.id] = true this.fallbackImageCollections[collection.id] = true
}, },
onScroll(e) {
const el = e.target
if (!el)
return
const bottom = (el.scrollHeight - el.scrollTop) <= el.clientHeight + 150
if (!bottom)
return
this.maxResultIndex += this.batchItems
},
},
mounted() {
this.$el.parentElement.addEventListener('scroll', this.onScroll)
},
unmounted() {
this.$el.parentElement.removeEventListener('scroll', this.onScroll)
}, },
} }
</script> </script>