Add buttons to go through posts

Closes #8
This commit is contained in:
Cadence Fish
2020-02-26 20:12:48 +13:00
parent becd2c2ec7
commit d32a12a134
8 changed files with 219 additions and 61 deletions

View File

@@ -18,6 +18,7 @@ const intersectionThreshold = 0
class NextPageController {
constructor() {
this.instance = null
this.activatedCallbacks = []
}
add() {
@@ -27,10 +28,15 @@ class NextPageController {
} else {
this.instance = null
}
this.activatedCallbacks.forEach(c => c())
}
activate() {
if (this.instance) this.instance.activate()
addActivatedCallback(callback) {
this.activatedCallbacks.push(callback)
}
async activate() {
if (this.instance) await this.instance.activate()
}
}
@@ -70,7 +76,7 @@ class NextPage extends FreezeWidth {
this.fetching = true
this.freeze("Loading...")
fetch(`/fragment/user/${this.element.getAttribute("data-username")}/${this.nextPageNumber}`).then(res => res.text()).then(text => {
return fetch(`/fragment/user/${this.element.getAttribute("data-username")}/${this.nextPageNumber}`).then(res => res.text()).then(text => {
q("#next-page-container").remove()
this.observer.disconnect()
q("#timeline").insertAdjacentHTML("beforeend", text)
@@ -81,7 +87,7 @@ class NextPage extends FreezeWidth {
activate() {
if (this.fetching) return
this.class("disabled")
this.fetch()
return this.fetch()
}
}