Infinite scroll fix in Feeds, search, channel view page

This commit is contained in:
Karlis Cudars 2021-10-30 21:48:41 +03:00
parent 44735f0d03
commit 540906b9e3
3 changed files with 15 additions and 12 deletions

View file

@ -54,14 +54,14 @@ export default {
},
activated() {
if (this.channel && !this.channel.error) document.title = this.channel.name + " - Piped";
window.addEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].addEventListener("scroll", this.handleScroll);
if (this.channel && !this.channel.error) this.updateWatched(this.channel.relatedStreams);
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].removeEventListener("scroll", this.handleScroll);
},
unmounted() {
window.removeEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchSubscribedStatus() {
@ -96,7 +96,8 @@ export default {
},
handleScroll() {
if (this.loading || !this.channel || !this.channel.nextpage) return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
var mainElem = document.getElementsByTagName("main")[0];
if (mainElem.offsetHeight + mainElem.scrollTop >= mainElem.scrollHeight - mainElem.clientHeight) {
this.loading = true;
this.fetchJson(this.apiUrl() + "/nextpage/channel/" + this.channel.id, {
nextpage: this.channel.nextpage,

View file

@ -142,13 +142,13 @@ export default {
activated() {
document.title = this.$t("titles.feed") + " - Piped";
if (this.videos.length > 0) this.updateWatched(this.videos);
window.addEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].addEventListener("scroll", this.handleScroll);
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].removeEventListener("scroll", this.handleScroll);
},
unmounted() {
window.removeEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchFeed() {
@ -178,7 +178,8 @@ export default {
this.videos = this.videosStore.slice(0, this.currentVideoCount);
},
handleScroll() {
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
var mainElem = document.getElementsByTagName("main")[0];
if (mainElem.offsetHeight + mainElem.scrollTop >= mainElem.scrollHeight - mainElem.clientHeight) {
this.loadMoreVideos();
}
},

View file

@ -144,13 +144,13 @@ export default {
this.updateResults();
},
activated() {
window.addEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].addEventListener("scroll", this.handleScroll);
},
deactivated() {
window.removeEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].removeEventListener("scroll", this.handleScroll);
},
unmounted() {
window.removeEventListener("scroll", this.handleScroll);
document.getElementsByTagName("main")[0].removeEventListener("scroll", this.handleScroll);
},
methods: {
async fetchResults() {
@ -165,7 +165,8 @@ export default {
},
handleScroll() {
if (this.loading || !this.results || !this.results.nextpage) return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
var mainElem = document.getElementsByTagName("main")[0];
if (mainElem.offsetHeight + mainElem.scrollTop >= mainElem.scrollHeight - mainElem.clientHeight) {
this.loading = true;
this.fetchJson(this.apiUrl() + "/nextpage/search", {
nextpage: this.results.nextpage,