Speakr is a personal, self-hosted web application designed for transcribing audio recordings
Python
Add loading overlay to prevent FOUC across all pages
Murtaza Nasire9bab6dd9840
diff --git a/static/css/loading.css b/static/css/loading.cssnew file mode 100644index 00000000..c7ff82b5--- /dev/null+++ b/static/css/loading.css@@ -0,0 +1,83 @@+/* Critical loading styles - inline these in the HTML head for instant loading */+.app-loading-overlay {+ position: fixed;+ top: 0;+ left: 0;+ right: 0;+ bottom: 0;+ background: var(--bg-primary, #1a1b26);+ z-index: 9999;+ display: flex;+ align-items: center;+ justify-content: center;+ transition: opacity 0.3s ease-out;+}++.app-loading-overlay.fade-out {+ opacity: 0;+ pointer-events: none;+}++.app-loading-content {+ text-align: center;+}++.app-loading-spinner {+ width: 50px;+ height: 50px;+ margin: 0 auto 20px;+ border: 3px solid rgba(255, 255, 255, 0.1);+ border-top-color: var(--text-accent, #7aa2f7);+ border-radius: 50%;+ animation: spin 1s linear infinite;+}++.app-loading-text {+ color: var(--text-muted, #a0a0b0);+ font-size: 14px;+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;+ letter-spacing: 0.5px;+}++.app-loading-logo {+ width: 60px;+ height: 60px;+ margin: 0 auto 20px;+ opacity: 0.8;+}++@keyframes spin {+ to {+ transform: rotate(360deg);+ }+}++/* Hide body content until ready */+body.app-loading {+ overflow: hidden;+}++body.app-loading > *:not(.app-loading-overlay) {+ opacity: 0;+}++/* Dark mode default colors */+@media (prefers-color-scheme: dark) {+ .app-loading-overlay {+ background: #1a1b26;+ }+}++/* Light mode if explicitly set */+body.light .app-loading-overlay {+ background: #ffffff;+}++body.light .app-loading-spinner {+ border-color: rgba(0, 0, 0, 0.1);+ border-top-color: #3b82f6;+}++body.light .app-loading-text {+ color: #6b7280;+}\ No newline at end of filediff --git a/static/js/app.js b/static/js/app.jsindex b8928fd2..9a6f75cb 100644--- a/static/js/app.js+++ b/static/js/app.js@@ -5489,4 +5489,21 @@ document.addEventListener('DOMContentLoaded', async () => {// Mount the appapp.mount('#app');++ // Hide loading overlay after Vue is mounted and ready+ Vue.nextTick(() => {+ const overlay = document.querySelector('.app-loading-overlay');+ if (overlay) {+ // Small delay to ensure everything is rendered+ setTimeout(() => {+ overlay.classList.add('fade-out');+ setTimeout(() => {+ overlay.remove();+ document.body.classList.remove('app-loading');+ }, 300);+ }, 100);+ } else {+ document.body.classList.remove('app-loading');+ }+ });});diff --git a/static/js/loading.js b/static/js/loading.jsnew file mode 100644index 00000000..c1fd2dc4--- /dev/null+++ b/static/js/loading.js@@ -0,0 +1,125 @@+/**+ * App loading overlay management+ * Prevents FOUC (Flash of Unstyled Content) during page initialization+ */++window.AppLoader = {+ initialized: false,+ readyChecks: [],++ /**+ * Initialize the loading system+ */+ init() {+ if (this.initialized) return;+ this.initialized = true;++ // Add loading class to body+ document.body.classList.add('app-loading');++ // Create loading overlay if it doesn't exist+ if (!document.querySelector('.app-loading-overlay')) {+ this.createOverlay();+ }++ // Set up ready checks+ this.setupReadyChecks();+ },++ /**+ * Create the loading overlay element+ */+ createOverlay() {+ const overlay = document.createElement('div');+ overlay.className = 'app-loading-overlay';+ overlay.innerHTML = `+ <div class="app-loading-content">+ <div class="app-loading-spinner"></div>+ <div class="app-loading-text">Loading...</div>+ </div>+ `;+ document.body.appendChild(overlay);+ },++ /**+ * Add a ready check condition+ */+ addReadyCheck(checkFn) {+ this.readyChecks.push(checkFn);+ },++ /**+ * Setup default ready checks+ */+ setupReadyChecks() {+ // Check if DOM is ready+ this.addReadyCheck(() => document.readyState === 'complete');++ // Check if styles are loaded+ this.addReadyCheck(() => {+ const styles = document.querySelector('link[href*="styles.css"]');+ return !styles || styles.sheet;+ });++ // Check if theme is initialized+ this.addReadyCheck(() => {+ const computed = window.getComputedStyle(document.documentElement);+ return computed.getPropertyValue('--bg-primary').trim() !== '';+ });+ },++ /**+ * Check if all conditions are met+ */+ isReady() {+ if (this.readyChecks.length === 0) return true;+ return this.readyChecks.every(check => {+ try {+ return check();+ } catch (e) {+ return false;+ }+ });+ },++ /**+ * Hide the loading overlay+ */+ hide() {+ const overlay = document.querySelector('.app-loading-overlay');+ if (overlay) {+ overlay.classList.add('fade-out');+ setTimeout(() => {+ overlay.remove();+ document.body.classList.remove('app-loading');+ }, 300);+ } else {+ document.body.classList.remove('app-loading');+ }+ },++ /**+ * Wait for app to be ready then hide overlay+ */+ async waitForReady(timeout = 5000) {+ const startTime = Date.now();++ const checkReady = () => {+ if (this.isReady() || Date.now() - startTime > timeout) {+ this.hide();+ } else {+ requestAnimationFrame(checkReady);+ }+ };++ // Start checking after a minimum display time+ setTimeout(checkReady, 300);+ }+};++// Auto-initialize on script load+if (document.readyState === 'loading') {+ document.addEventListener('DOMContentLoaded', () => AppLoader.init());+} else {+ AppLoader.init();+}\ No newline at end of filediff --git a/templates/account.html b/templates/account.htmlindex c22d41b0..30cd23ea 100644--- a/templates/account.html+++ b/templates/account.html@@ -12,6 +12,11 @@<link rel="stylesheet" href="{{ url_for('static', filename='vendor/css/fontawesome.min.css') }}"><link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}"><script src="{{ url_for('static', filename='js/i18n.js') }}"></script>++ <!-- Loading overlay to prevent FOUC -->+ {% include 'includes/loading_overlay.html' %}+ <script src="{{ url_for('static', filename='js/loading.js') }}"></script>+<script>// Initialize i18nlet t = (key) => key; // Default fallback@@ -1219,6 +1224,11 @@// Initialize i18nawait initializeI18n();+ // Hide loading overlay after everything is ready+ if (window.AppLoader) {+ AppLoader.waitForReady();+ }+// Setup scroll indicators for tabsconst tabsContainer = document.getElementById('tabs-container');const leftIndicator = document.getElementById('left-scroll-indicator');diff --git a/templates/admin.html b/templates/admin.htmlindex 85489dd5..ccb2d5e9 100644--- a/templates/admin.html+++ b/templates/admin.html@@ -5,6 +5,10 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="csrf-token" content="{{ csrf_token() }}"><title>Admin Dashboard - Speakr</title>++ <!-- Loading overlay to prevent FOUC - MUST be first -->+ {% include 'includes/loading_overlay.html' %}+<link rel="icon" href="{{ url_for('static', filename='img/favicon.ico') }}" type="image/svg+xml"><!-- All dependencies bundled locally for offline support --><script src="{{ url_for('static', filename='vendor/js/tailwind.min.js') }}"></script>@@ -14,7 +18,13 @@<link rel="stylesheet" href="{{ url_for('static', filename='vendor/css/fontawesome.min.css') }}"><link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}"><script src="{{ url_for('static', filename='js/i18n.js') }}"></script>+ <script src="{{ url_for('static', filename='js/loading.js') }}"></script><style>+ /* Hide Vue content until compiled */+ [v-cloak] {+ display: none !important;+ }+/* Hide scrollbar for tabs */.scrollbar-hide {-ms-overflow-style: none;@@ -84,7 +94,7 @@</script></head><body class="bg-[var(--bg-primary)] text-[var(--text-primary)]">- <div id="app" class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 flex flex-col min-h-screen">+ <div id="app" v-cloak class="container mx-auto px-4 sm:px-6 lg:px-8 py-6 flex flex-col min-h-screen"><header class="flex justify-between items-center mb-6 pb-4 border-b border-[var(--border-primary)]"><h1 class="text-3xl font-bold text-[var(--text-primary)]"><a href="{{ url_for('index') }}" class="flex items-center">@@ -1748,6 +1758,22 @@ Summarization Instructions:},delimiters: ['${', '}'] // Use different delimiters to avoid conflict with Flask's Jinja2}).mount('#app');++ // Hide loading overlay after Vue is mounted+ Vue.nextTick(() => {+ const overlay = document.querySelector('.app-loading-overlay');+ if (overlay) {+ setTimeout(() => {+ overlay.classList.add('fade-out');+ setTimeout(() => {+ overlay.remove();+ document.body.classList.remove('app-loading');+ }, 300);+ }, 100);+ } else {+ document.body.classList.remove('app-loading');+ }+ });}); // End of initializeI18n().then()</script></body>diff --git a/templates/includes/loading_overlay.html b/templates/includes/loading_overlay.htmlnew file mode 100644index 00000000..c9d20324--- /dev/null+++ b/templates/includes/loading_overlay.html@@ -0,0 +1,60 @@+<!-- Loading Overlay - Prevents FOUC -->+<style>+ /* Inline critical loading styles for instant rendering */+ .app-loading-overlay {+ position: fixed;+ top: 0;+ left: 0;+ right: 0;+ bottom: 0;+ background: #1a1b26;+ z-index: 9999;+ display: flex;+ align-items: center;+ justify-content: center;+ transition: opacity 0.3s ease-out;+ }+ .app-loading-overlay.fade-out {+ opacity: 0;+ pointer-events: none;+ }+ .app-loading-content {+ text-align: center;+ }+ .app-loading-spinner {+ width: 50px;+ height: 50px;+ margin: 0 auto 20px;+ border: 3px solid rgba(255, 255, 255, 0.1);+ border-top-color: #7aa2f7;+ border-radius: 50%;+ animation: spin 1s linear infinite;+ }+ .app-loading-text {+ color: #a0a0b0;+ font-size: 14px;+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;+ letter-spacing: 0.5px;+ }+ @keyframes spin {+ to { transform: rotate(360deg); }+ }+ body.app-loading { overflow: hidden; }+ body.app-loading > *:not(.app-loading-overlay) { opacity: 0; }+ body.light .app-loading-overlay { background: #ffffff; }+ body.light .app-loading-spinner {+ border-color: rgba(0, 0, 0, 0.1);+ border-top-color: #3b82f6;+ }+ body.light .app-loading-text { color: #6b7280; }+</style>+<script>+ // Immediate loading overlay initialization+ (function() {+ document.body.classList.add('app-loading');+ var overlay = document.createElement('div');+ overlay.className = 'app-loading-overlay';+ overlay.innerHTML = '<div class="app-loading-content"><div class="app-loading-spinner"></div><div class="app-loading-text">Loading Speakr...</div></div>';+ document.body.appendChild(overlay);+ })();+</script>\ No newline at end of filediff --git a/templates/index.html b/templates/index.htmlindex 4158a299..fc153f5c 100644--- a/templates/index.html+++ b/templates/index.html@@ -5,6 +5,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="csrf-token" content="{{ csrf_token() }}"><title>Speakr - Audio Transcription & Summarization</title>+ {% include 'includes/loading_overlay.html' %}<!-- All dependencies bundled locally for offline support --><script src="{{ url_for('static', filename='vendor/js/tailwind.min.js') }}"></script><script src="{{ url_for('static', filename='vendor/js/vue.global.js') }}"></script>diff --git a/templates/inquire.html b/templates/inquire.htmlindex 812e1110..52e1143e 100644--- a/templates/inquire.html+++ b/templates/inquire.html@@ -17,6 +17,11 @@<script src="{{ url_for('static', filename='js/i18n.js') }}"></script><link rel="icon" href="{{ url_for('static', filename='img/favicon.ico') }}"><link rel="icon" type="image/png" sizes="32x32" href="{{ url_for('static', filename='img/icon-32x32.png') }}">++ <!-- Loading overlay to prevent FOUC -->+ {% include 'includes/loading_overlay.html' %}+ <script src="{{ url_for('static', filename='js/loading.js') }}"></script>+<script>tailwind.config = {darkMode: 'class',@@ -890,6 +895,13 @@},delimiters: ['${', '}']}).mount('#inquire-app');++ // Hide loading overlay after app mounts+ Vue.nextTick(() => {+ if (window.AppLoader) {+ AppLoader.waitForReady();+ }+ });});</script></body>diff --git a/templates/login.html b/templates/login.htmlindex eecb9886..6db6766b 100644--- a/templates/login.html+++ b/templates/login.html@@ -10,6 +10,11 @@<!-- All dependencies bundled locally for offline support --><link rel="stylesheet" href="{{ url_for('static', filename='vendor/css/fontawesome.min.css') }}"><link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">++ <!-- Loading overlay to prevent FOUC -->+ {% include 'includes/loading_overlay.html' %}+ <script src="{{ url_for('static', filename='js/loading.js') }}"></script>+<script>// Function to apply the theme based on localStoragefunction applyTheme() {@@ -119,5 +124,14 @@Speakr © {{ now.year }}</footer></div>++ <script>+ // Hide loading overlay when page is ready+ document.addEventListener('DOMContentLoaded', function() {+ if (window.AppLoader) {+ AppLoader.waitForReady();+ }+ });+ </script></body></html>diff --git a/templates/register.html b/templates/register.htmlindex 53030c92..92397b88 100644--- a/templates/register.html+++ b/templates/register.html@@ -10,6 +10,11 @@<!-- All dependencies bundled locally for offline support --><link rel="stylesheet" href="{{ url_for('static', filename='vendor/css/fontawesome.min.css') }}"><link rel="stylesheet" href="{{ url_for('static', filename='css/styles.css') }}">++ <!-- Loading overlay to prevent FOUC -->+ {% include 'includes/loading_overlay.html' %}+ <script src="{{ url_for('static', filename='js/loading.js') }}"></script>+<script>// Function to apply the theme based on localStoragefunction applyTheme() {@@ -143,5 +148,14 @@Speakr © {{ now.year }}</footer></div>++ <script>+ // Hide loading overlay when page is ready+ document.addEventListener('DOMContentLoaded', function() {+ if (window.AppLoader) {+ AppLoader.waitForReady();+ }+ });+ </script></body></html>diff --git a/templates/share.html b/templates/share.htmlindex 09e7cc7a..3f95d544 100644--- a/templates/share.html+++ b/templates/share.html@@ -13,6 +13,11 @@<script src="{{ url_for('static', filename='vendor/js/axios.min.js') }}"></script><!-- All dependencies bundled locally for offline support --><link rel="stylesheet" href="{{ url_for('static', filename='vendor/css/fontawesome.min.css') }}">++ <!-- Loading overlay to prevent FOUC -->+ {% include 'includes/loading_overlay.html' %}+ <script src="{{ url_for('static', filename='js/loading.js') }}"></script>+<script>tailwind.config = {darkMode: 'class',@@ -469,6 +474,13 @@app.config.compilerOptions.delimiters = ['${', '}'];app.mount('#app');++ // Hide loading overlay after app mounts+ Vue.nextTick(() => {+ if (window.AppLoader) {+ AppLoader.waitForReady();+ }+ });</script></body></html>