Refactor scroll distance calculation and prefetch logic for mobile layout in main and admin templates

This commit is contained in:
2026-04-19 21:36:41 +02:00
parent e2f8da213a
commit 3e48aa23cc
3 changed files with 8 additions and 7 deletions
Submodule Web/pwa-app deleted from da45c25039
+4 -3
View File
@@ -781,10 +781,10 @@
styles.flexDirection === 'column'; styles.flexDirection === 'column';
const distanceToEnd = isMobileLayout const distanceToEnd = isMobileLayout
? itemsContainer.scrollHeight - (itemsContainer.scrollTop + itemsContainer.clientHeight) ? Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) - (window.scrollY + window.innerHeight)
: itemsContainer.scrollWidth - (itemsContainer.scrollLeft + itemsContainer.clientWidth); : itemsContainer.scrollWidth - (itemsContainer.scrollLeft + itemsContainer.clientWidth);
const prefetchThreshold = isMobileLayout const prefetchThreshold = isMobileLayout
? Math.max(220, itemsContainer.clientHeight * 0.9) ? window.innerHeight * 1.5
: Math.max(260, itemsContainer.clientWidth * 1.4); : Math.max(260, itemsContainer.clientWidth * 1.4);
if (distanceToEnd > prefetchThreshold) { if (distanceToEnd > prefetchThreshold) {
return; return;
@@ -1167,6 +1167,7 @@
if (!mainItemsScrollPrefetchBound) { if (!mainItemsScrollPrefetchBound) {
itemsContainer.addEventListener('scroll', maybePrefetchMainItems, { passive: true }); itemsContainer.addEventListener('scroll', maybePrefetchMainItems, { passive: true });
window.addEventListener('scroll', maybePrefetchMainItems, { passive: true });
mainItemsScrollPrefetchBound = true; mainItemsScrollPrefetchBound = true;
} }
@@ -1188,7 +1189,7 @@
updateMainItemsLoadingIndicator(); updateMainItemsLoadingIndicator();
}); });
}, { }, {
root: itemsContainer, root: isMobileLayout ? null : itemsContainer,
threshold: 0.15, threshold: 0.15,
rootMargin: isMobileLayout ? '0px 0px 900px 0px' : '0px 900px 0px 0px' rootMargin: isMobileLayout ? '0px 0px 900px 0px' : '0px 900px 0px 0px'
}); });
+4 -3
View File
@@ -3397,10 +3397,10 @@ document.addEventListener('DOMContentLoaded', ()=>{
styles.flexDirection === 'column'; styles.flexDirection === 'column';
const distanceToEnd = isMobileLayout const distanceToEnd = isMobileLayout
? itemsContainer.scrollHeight - (itemsContainer.scrollTop + itemsContainer.clientHeight) ? Math.max(document.body.scrollHeight, document.documentElement.scrollHeight) - (window.scrollY + window.innerHeight)
: itemsContainer.scrollWidth - (itemsContainer.scrollLeft + itemsContainer.clientWidth); : itemsContainer.scrollWidth - (itemsContainer.scrollLeft + itemsContainer.clientWidth);
const prefetchThreshold = isMobileLayout const prefetchThreshold = isMobileLayout
? Math.max(220, itemsContainer.clientHeight * 0.9) ? window.innerHeight * 1.5
: Math.max(260, itemsContainer.clientWidth * 1.4); : Math.max(260, itemsContainer.clientWidth * 1.4);
if (distanceToEnd > prefetchThreshold) { if (distanceToEnd > prefetchThreshold) {
return; return;
@@ -3772,6 +3772,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
if (!mainAdminItemsScrollPrefetchBound) { if (!mainAdminItemsScrollPrefetchBound) {
itemsContainer.addEventListener('scroll', maybePrefetchMainAdminItems, { passive: true }); itemsContainer.addEventListener('scroll', maybePrefetchMainAdminItems, { passive: true });
window.addEventListener('scroll', maybePrefetchMainAdminItems, { passive: true });
mainAdminItemsScrollPrefetchBound = true; mainAdminItemsScrollPrefetchBound = true;
} }
@@ -3793,7 +3794,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
updateMainAdminItemsLoadingIndicator(); updateMainAdminItemsLoadingIndicator();
}); });
}, { }, {
root: itemsContainer, root: isMobileLayout ? null : itemsContainer,
threshold: 0.15, threshold: 0.15,
rootMargin: isMobileLayout ? '0px 0px 900px 0px' : '0px 900px 0px 0px' rootMargin: isMobileLayout ? '0px 0px 900px 0px' : '0px 900px 0px 0px'
}); });