fix: simplify code for hiding form
This commit is contained in:
@@ -408,38 +408,15 @@ function hideFormForInitialSubmission() {
|
|||||||
rootNode.style.setProperty(opacityVariableName, "1");
|
rootNode.style.setProperty(opacityVariableName, "1");
|
||||||
};
|
};
|
||||||
|
|
||||||
/** @type {number | undefined} */
|
// If this file gets more complicated, it might make sense to set up the
|
||||||
let intervalId = undefined;
|
// timeout and event listener so that if one triggers, it cancels the other,
|
||||||
const pollingTimeoutMs = 5_000;
|
// but having restoreOpacity run more than once is a no-op for right now.
|
||||||
let pollAttempts = 0;
|
// Not a big deal if these don't get cleaned up.
|
||||||
|
|
||||||
const checkIfSafeToHideForm = () => {
|
/** @type {HTMLFormElement | null} */
|
||||||
/** @type {HTMLFormElement | null} */
|
const form = document.querySelector("web-client-form > form");
|
||||||
const form = document.querySelector("web-client-form > form");
|
form?.addEventListener("submit", restoreOpacity, { once: true });
|
||||||
if (form === null) {
|
window.setTimeout(restoreOpacity, 5_000);
|
||||||
pollAttempts++;
|
|
||||||
const elapsedTime = pollAttempts * SCREEN_POLL_INTERVAL_MS;
|
|
||||||
|
|
||||||
if (elapsedTime >= pollingTimeoutMs) {
|
|
||||||
restoreOpacity();
|
|
||||||
window.clearInterval(intervalId);
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this file gets more complicated, it might make sense to set up the
|
|
||||||
// timeout and event listener so that if one triggers, it cancels the other,
|
|
||||||
// but having restoreOpacity run more than once is a no-op for right now.
|
|
||||||
// Not a big deal if these don't get cleaned up.
|
|
||||||
window.setTimeout(restoreOpacity, 5_000);
|
|
||||||
form.addEventListener("submit", restoreOpacity, { once: true });
|
|
||||||
};
|
|
||||||
|
|
||||||
intervalId = window.setInterval(
|
|
||||||
checkIfSafeToHideForm,
|
|
||||||
SCREEN_POLL_INTERVAL_MS,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupFormOverrides() {
|
function setupFormOverrides() {
|
||||||
|
|||||||
Reference in New Issue
Block a user