Files
FACULTATE-LICENTA/Desktop App/render/client/js/helpers.js
T

48 lines
1.6 KiB
JavaScript

function fadeIn() {
document.querySelector('.container').classList.remove('fade-out');
document.querySelector('.container').classList.add('fade-in');
}
function fadeOut(destination) {
const container = document.querySelector('.container');
container.classList.remove('fade-in');
container.classList.add('fade-out');
console.log(destination);
setTimeout(() => {}, 5000);
container.addEventListener('animationend', async () => {
try {
await window.uiAPI.changeContent(destination);
console.log('Navigated to', destination);
} catch (error) {
console.error('Error navigating:', error);
}
});
}
async function waitForResponse() {
return new Promise((resolve) => {
const idResponseCheck = setInterval(async () => {
if (await window.networkAPI.hasResponseArrived()) {
clearInterval(idResponseCheck);
resolve(await window.networkAPI.getLastUcResult()); // Resolve the response or null if not available
}
}, 100); // Check every 100 milliseconds if the response has arrived
});
}
function toggleScroll(idComponent, scrollHeight = 180) {
const element = document.getElementById(idComponent); // Using getElementById
if (!element) {
console.error(`Element with ID '${idComponent}' not found.`);
return;
}
if (element.scrollHeight > scrollHeight) {
element.style.overflowY = 'auto'; // Enable scroll if content overflows
} else {
element.style.overflowY = 'hidden'; // Disable scroll if content fits
}
}