Fix 'preloader' overlay being removed too early

This commit is contained in:
Wolfsblvt
2024-06-30 22:03:38 +02:00
parent 7344b63109
commit 47f00d3755
2 changed files with 12 additions and 4 deletions

View File

@ -5,6 +5,8 @@ const ELEMENT_ID = 'loader';
/** @type {Popup} */
let loaderPopup;
let preloaderYoinked = false;
export function showLoader() {
// Two loaders don't make sense. Don't await, we can overlay the old loader while it closes
if (loaderPopup) loaderPopup.complete(POPUP_RESULT.CANCELLED);
@ -21,6 +23,10 @@ export function showLoader() {
}
export async function hideLoader() {
// Yoink preloader entirely; it only exists to cover up unstyled content while loading JS
// If it's present, we remove it once and then it's gone.
yoinkPreloader();
if (!loaderPopup) {
console.warn('There is no loader showing to hide');
return Promise.resolve();
@ -48,3 +54,8 @@ export async function hideLoader() {
});
}
function yoinkPreloader() {
if (preloaderYoinked) return;
document.getElementById('preloader').remove();
preloaderYoinked = true;
}