mirror of
https://github.com/basicswap/basicswap.git
synced 2025-01-31 23:05:55 +00:00
ui/js: Optimization tweaks.
This commit is contained in:
parent
73ab5e7391
commit
9418ea4385
1 changed files with 147 additions and 74 deletions
|
@ -89,6 +89,73 @@ const totalPagesSpan = document.getElementById('totalPages');
|
||||||
const lastRefreshTimeSpan = document.getElementById('lastRefreshTime');
|
const lastRefreshTimeSpan = document.getElementById('lastRefreshTime');
|
||||||
const newEntriesCountSpan = document.getElementById('newEntriesCount');
|
const newEntriesCountSpan = document.getElementById('newEntriesCount');
|
||||||
|
|
||||||
|
const ScrollOptimizer = {
|
||||||
|
scrollTimeout: null,
|
||||||
|
isScrolling: false,
|
||||||
|
|
||||||
|
init() {
|
||||||
|
document.body.classList.add('optimize-scroll');
|
||||||
|
window.addEventListener('scroll', this.handleScroll.bind(this), { passive: true });
|
||||||
|
},
|
||||||
|
|
||||||
|
handleScroll() {
|
||||||
|
if (!this.isScrolling) {
|
||||||
|
document.body.classList.add('is-scrolling');
|
||||||
|
this.isScrolling = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.scrollTimeout) {
|
||||||
|
clearTimeout(this.scrollTimeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.scrollTimeout = setTimeout(() => {
|
||||||
|
document.body.classList.remove('is-scrolling');
|
||||||
|
this.isScrolling = false;
|
||||||
|
}, 150);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const scrollStyles = document.createElement('style');
|
||||||
|
scrollStyles.textContent = `
|
||||||
|
.optimize-scroll {
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-scrolling .overflow-x-auto {
|
||||||
|
will-change: transform;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.is-scrolling * {
|
||||||
|
animation: none !important;
|
||||||
|
transition: none !important;
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
document.head.appendChild(scrollStyles);
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
ScrollOptimizer.init();
|
||||||
|
});
|
||||||
|
|
||||||
|
let isTableRendering = false;
|
||||||
|
const tableContainer = document.querySelector('.overflow-x-auto');
|
||||||
|
|
||||||
|
function startTableRender() {
|
||||||
|
isTableRendering = true;
|
||||||
|
if (tableContainer) {
|
||||||
|
tableContainer.style.overflow = 'hidden';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function finishTableRender() {
|
||||||
|
isTableRendering = false;
|
||||||
|
setTimeout(() => {
|
||||||
|
if (tableContainer) {
|
||||||
|
tableContainer.style.overflow = 'auto';
|
||||||
|
}
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
|
||||||
// MANAGER OBJECTS
|
// MANAGER OBJECTS
|
||||||
const WebSocketManager = {
|
const WebSocketManager = {
|
||||||
ws: null,
|
ws: null,
|
||||||
|
@ -1388,6 +1455,8 @@ function handleNoOffersScenario() {
|
||||||
|
|
||||||
async function updateOffersTable() {
|
async function updateOffersTable() {
|
||||||
try {
|
try {
|
||||||
|
startTableRender();
|
||||||
|
|
||||||
const PRICES_CACHE_KEY = 'prices_coingecko';
|
const PRICES_CACHE_KEY = 'prices_coingecko';
|
||||||
const cachedPrices = CacheManager.get(PRICES_CACHE_KEY);
|
const cachedPrices = CacheManager.get(PRICES_CACHE_KEY);
|
||||||
|
|
||||||
|
@ -1426,6 +1495,7 @@ async function updateOffersTable() {
|
||||||
cleanupRow(row);
|
cleanupRow(row);
|
||||||
});
|
});
|
||||||
handleNoOffersScenario();
|
handleNoOffersScenario();
|
||||||
|
finishTableRender();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1458,6 +1528,8 @@ async function updateOffersTable() {
|
||||||
if (tableRateModule?.initializeTable) {
|
if (tableRateModule?.initializeTable) {
|
||||||
tableRateModule.initializeTable();
|
tableRateModule.initializeTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
finishTableRender();
|
||||||
});
|
});
|
||||||
|
|
||||||
lastRefreshTime = Date.now();
|
lastRefreshTime = Date.now();
|
||||||
|
@ -1476,6 +1548,7 @@ async function updateOffersTable() {
|
||||||
An error occurred while updating the offers table. Please try again later.
|
An error occurred while updating the offers table. Please try again later.
|
||||||
</td>
|
</td>
|
||||||
</tr>`;
|
</tr>`;
|
||||||
|
finishTableRender();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue