Merge pull request #8509 from aignatov-bio/ai-sci-11911-fix-results-infinite-scroll

Fix results infinite scroll [SCI-11911]
This commit is contained in:
Martin Artnik 2025-05-26 12:36:05 +02:00 committed by GitHub
commit 181e92735a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -86,14 +86,14 @@ export default {
},
mounted() {
this.userSettingsUrl = document.querySelector('meta[name="user-settings-url"]').getAttribute('content');
window.addEventListener('scroll', this.loadResults, false);
window.addEventListener('scroll', this.infiniteScrollLoad, false);
window.addEventListener('scroll', this.initStackableHeaders, false);
this.nextPageUrl = this.url;
this.loadResults();
this.initStackableHeaders();
},
beforeUnmount() {
window.removeEventListener('scroll', this.loadResults, false);
window.removeEventListener('scroll', this.infiniteScrollLoad, false);
window.removeEventListener('scroll', this.initStackableHeaders, false);
},
methods: {
@ -110,10 +110,14 @@ export default {
this.loadResults();
});
},
infiniteScrollLoad() {
if (window.scrollY + window.innerHeight >= document.body.scrollHeight - 20) {
this.loadResults();
}
},
loadResults() {
if (this.nextPageUrl === null || this.loadingPage) return;
if (window.scrollY + window.innerHeight >= document.body.scrollHeight - 20) {
this.loadingPage = true;
const params = this.sort ? { ...this.filters, sort: this.sort } : { ...this.filters };
axios.get(this.nextPageUrl, { params }).then((response) => {
@ -122,7 +126,6 @@ export default {
this.nextPageUrl = response.data.links.next;
this.loadingPage = false;
});
}
},
setSort(sort) {
this.sort = sort;