feat: add splash screen with logo on app load and after login

- Show sofarr logo splash screen while app initialises
- On page load: splash stays visible while checking auth and fetching data
- After login: splash reappears while fetching initial downloads
- Minimum 1.2s display with smooth fade-out transition
- Subtle pulse animation on the logo
This commit is contained in:
2026-05-15 23:14:16 +01:00
parent bafa03aac2
commit b146a180d0
4 changed files with 68 additions and 2 deletions

View File

@@ -4,6 +4,7 @@ let refreshInterval = null;
let currentRefreshRate = 5000; // default 5 seconds
let isAdmin = false;
let showAll = false;
const SPLASH_MIN_MS = 1200; // minimum splash display time
// Apply saved theme immediately (before DOMContentLoaded to avoid flash)
(function() {
@@ -63,7 +64,30 @@ function stopAutoRefresh() {
}
}
function showSplash() {
const splash = document.getElementById('splash-screen');
splash.style.display = 'flex';
splash.style.opacity = '1';
splash.classList.remove('fade-out');
}
function dismissSplash(startTime) {
return new Promise(resolve => {
const elapsed = Date.now() - (startTime || 0);
const remaining = Math.max(0, SPLASH_MIN_MS - elapsed);
setTimeout(() => {
const splash = document.getElementById('splash-screen');
splash.classList.add('fade-out');
splash.addEventListener('transitionend', () => {
splash.style.display = 'none';
resolve();
}, { once: true });
}, remaining);
});
}
async function checkAuthentication() {
const splashStart = Date.now();
try {
const response = await fetch('/api/auth/me');
const data = await response.json();
@@ -72,13 +96,16 @@ async function checkAuthentication() {
currentUser = data.user;
isAdmin = !!data.user.isAdmin;
showDashboard();
fetchUserDownloads(true);
await fetchUserDownloads(true);
startAutoRefresh();
await dismissSplash(splashStart);
} else {
await dismissSplash(splashStart);
showLogin();
}
} catch (err) {
console.error('Authentication check failed:', err);
await dismissSplash(splashStart);
showLogin();
}
}
@@ -103,9 +130,12 @@ async function handleLogin(e) {
if (data.success) {
currentUser = data.user;
isAdmin = !!data.user.isAdmin;
showSplash();
showDashboard();
fetchUserDownloads(true);
const splashStart = Date.now();
await fetchUserDownloads(true);
startAutoRefresh();
await dismissSplash(splashStart);
} else {
showLoginError(data.error || 'Login failed');
}