fix: prevent jump to table head on continuous scroll load

This commit is contained in:
Christoph Kluge 2024-11-29 12:00:28 +01:00
parent 5766945006
commit 5da6baf828

View File

@ -107,7 +107,11 @@
let jobs = [] let jobs = []
$: if ($initialized && $jobsStore.data) { $: if ($initialized && $jobsStore.data) {
if (usePaging) {
jobs = [...$jobsStore.data.jobs.items] jobs = [...$jobsStore.data.jobs.items]
} else { // Prevents jump to table head: Extends existing list instead of rendering new list
jobs = jobs.concat([...$jobsStore.data.jobs.items])
}
} }
$: matchedJobs = $jobsStore.data != null ? $jobsStore.data.jobs.count : -1; $: matchedJobs = $jobsStore.data != null ? $jobsStore.data.jobs.count : -1;
@ -170,7 +174,6 @@
} }
if (!usePaging) { if (!usePaging) {
let scrollMultiplier = 1
window.addEventListener('scroll', () => { window.addEventListener('scroll', () => {
let { let {
scrollTop, scrollTop,
@ -181,8 +184,7 @@
// Add 100 px offset to trigger load earlier // Add 100 px offset to trigger load earlier
if (scrollTop + clientHeight >= scrollHeight - 100 && $jobsStore.data != null && $jobsStore.data.jobs.hasNextPage) { if (scrollTop + clientHeight >= scrollHeight - 100 && $jobsStore.data != null && $jobsStore.data.jobs.hasNextPage) {
let pendingPaging = { ...paging } let pendingPaging = { ...paging }
scrollMultiplier += 1 pendingPaging.page += 1
pendingPaging.itemsPerPage = itemsPerPage * scrollMultiplier
paging = pendingPaging paging = pendingPaging
}; };
}); });