Implement better handling of channel page loading.

This commit is contained in:
Kavin 2022-11-01 15:15:12 +00:00
parent 00e7d22bdb
commit 649aad7a89
No known key found for this signature in database
GPG key ID: 49451E4482CC5BCD

View file

@ -142,7 +142,13 @@ export default {
}); });
}, },
handleScroll() { handleScroll() {
if (this.loading || !this.channel || !this.channel.nextpage) return; if (
this.loading ||
!this.channel ||
!this.channel.nextpage ||
(this.selectedTab != 0 && !this.tabs[this.selectedTab].tabNextPage)
)
return;
if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) { if (window.innerHeight + window.scrollY >= document.body.offsetHeight - window.innerHeight) {
this.loading = true; this.loading = true;
if (this.selectedTab == 0) { if (this.selectedTab == 0) {
@ -165,11 +171,12 @@ export default {
fetchChannelTabNextPage() { fetchChannelTabNextPage() {
this.fetchJson(this.apiUrl() + "/channels/tabs", { this.fetchJson(this.apiUrl() + "/channels/tabs", {
data: this.tabs[this.selectedTab].data, data: this.tabs[this.selectedTab].data,
nextpage: this.tabNextPage, nextpage: this.tabs[this.selectedTab].tabNextPage,
}).then(json => { }).then(json => {
this.tabNextPage = json.nextpage; this.tabs[this.selectedTab].tabNextPage = json.nextpage;
this.loading = false; this.loading = false;
json.content.map(item => this.contentItems.push(item)); json.content.map(item => this.contentItems.push(item));
this.tabs[this.selectedTab].content = this.contentItems;
}); });
}, },
subscribeHandler() { subscribeHandler() {
@ -216,11 +223,15 @@ export default {
this.contentItems = this.channel.relatedStreams; this.contentItems = this.channel.relatedStreams;
return; return;
} }
if (this.tabs[index].content) {
this.contentItems = this.tabs[index].content;
return;
}
this.fetchJson(this.apiUrl() + "/channels/tabs", { this.fetchJson(this.apiUrl() + "/channels/tabs", {
data: this.tabs[index].data, data: this.tabs[index].data,
}).then(tab => { }).then(tab => {
this.contentItems = tab.content; this.contentItems = this.tabs[index].content = tab.content;
this.tabNextPage = tab.nextpage; this.tabs[this.selectedTab].tabNextPage = tab.nextpage;
}); });
}, },
}, },