Files
taxbaik/TaxBaik.Web/wwwroot/js/admin-session.js
T
kjh2064 27f57ff925
TaxBaik CI/CD / build-and-deploy (push) Successful in 1m0s
fix: guarantee loading indicator hides with 3-second timeout
**Issue**: Loading indicator remained visible, intercepting all user interactions (pointer-events: auto blocks clicks)

**Root cause**: Multiple detection methods insufficient, race condition between JavaScript execution and Blazor initialization

**Solution**: Add guaranteed 3-second timeout + multiple detection methods
- Method 1: 3000ms timeout (guaranteed)
- Method 2: Detect when 10+ MudBlazor components appear
- Method 3: Hide when readystatechange to 'interactive' or 'complete'

**Failsafe**: Even if Blazor never fires events, loading WILL hide after 3 seconds max

**Result**:
- Loading shows: immediate on page load
- Loading hides: within 1-3 seconds (whichever is first)
- User can interact: guaranteed by 3-second timeout at latest

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-28 15:04:39 +09:00

69 lines
2.5 KiB
JavaScript

window.taxbaikAdminSession = {
syncRouteClass: function () {
document.documentElement.classList.toggle(
'admin-login-route',
window.location.pathname.toLowerCase().endsWith('/admin/login'));
},
clearAuthToken: function () {
try {
localStorage.removeItem('auth_token');
} catch {
// Ignore storage errors; redirect still recovers the session.
}
},
watchReconnect: function () {
window.taxbaikAdminSession.syncRouteClass();
window.addEventListener('popstate', window.taxbaikAdminSession.syncRouteClass);
// Hide loading indicator after Blazor initializes
const loadingOverlay = document.getElementById('blazor-loading');
if (loadingOverlay) {
const hideLoading = () => {
if (loadingOverlay.classList.contains('show')) {
loadingOverlay.classList.remove('show');
}
};
// Method 1: Hide after 3 seconds (guaranteed timeout)
setTimeout(hideLoading, 3000);
// Method 2: Hide when Blazor components appear (faster if available)
const observer = new MutationObserver(() => {
const mudElements = document.querySelectorAll('[class*="mud-"]').length;
if (mudElements > 10) {
hideLoading();
observer.disconnect();
}
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: true
});
// Method 3: Hide when page is interactive
document.addEventListener('readystatechange', () => {
if (document.readyState === 'interactive' || document.readyState === 'complete') {
setTimeout(hideLoading, 500);
}
});
}
const modal = document.getElementById('components-reconnect-modal');
if (!modal) {
return;
}
const reloadOnRejectedCircuit = () => {
const className = modal.className || '';
if (className.includes('components-reconnect-failed') ||
className.includes('components-reconnect-rejected')) {
window.setTimeout(() => window.location.reload(), 1500);
}
};
new MutationObserver(reloadOnRejectedCircuit)
.observe(modal, { attributes: true, attributeFilter: ['class'] });
}
};