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