mirror of
https://github.com/docusealco/docuseal
synced 2026-11-04 14:42:32 -05:00
add infinite scroll
This commit is contained in:
1 parent
d3cc2e1ca8
commit
8cb0a7a020
21 files changed
+179
-10
No files matched your search
@@ -0,0 +1,41 @@
|
||||
import { renderStreamMessage } from '@hotwired/turbo'
|
||||
|
||||
export default class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
if (!this.dataset.src) {
|
||||
this.remove()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
this.observer = new IntersectionObserver((entries) => {
|
||||
if (entries.some((entry) => entry.isIntersecting)) {
|
||||
this.load()
|
||||
}
|
||||
}, { rootMargin: '400px' })
|
||||
|
||||
this.observer.observe(this)
|
||||
}
|
||||
|
||||
disconnectedCallback () {
|
||||
this.observer?.disconnect()
|
||||
}
|
||||
|
||||
load () {
|
||||
if (this.loading || !this.dataset.src) return
|
||||
|
||||
this.loading = true
|
||||
|
||||
fetch(this.dataset.src, {
|
||||
headers: { 'X-Turbo-Infinite-Scroll': 'true' }
|
||||
}).then(async (response) => {
|
||||
if (!response.ok) return
|
||||
|
||||
delete this.dataset.src
|
||||
|
||||
renderStreamMessage(await response.text())
|
||||
}).finally(() => {
|
||||
this.loading = false
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user