Raí Santos commited on
Commit
b0d6f42
·
1 Parent(s): 0f02db5
Files changed (2) hide show
  1. public/app.js +10 -48
  2. public/app.min.js +0 -0
public/app.js CHANGED
@@ -25,11 +25,6 @@ class FitnessApp {
25
  this.activeTimeouts = new Set();
26
  this.activeVideoHandlers = null;
27
 
28
- // 🐛 BUG FIX #2: Flags de controle de inicialização
29
- this._appFullyInitialized = false;
30
- this._beforeUnloadSetup = false;
31
- this._eventListenersSetup = false; // 🐛 BUG FIX #4: Prevenir event listeners duplicados
32
-
33
  // 🎥 Video and Audio Configuration - Smart detection
34
  // Check if running as PWA (installed app) or has ?source=pwa parameter
35
  const urlParams = new URLSearchParams(window.location.search);
@@ -313,16 +308,10 @@ class FitnessApp {
313
  this.loadAchievements();
314
  this.setupPWA();
315
 
316
- // 🐛 BUG FIX #2: Marcar app como completamente inicializado
317
- this._appFullyInitialized = true;
318
-
319
  // 🐛 NEW BUG FIX #2: Cleanup timers quando a página descarrega
320
- if (!this._beforeUnloadSetup) {
321
- window.addEventListener('beforeunload', () => {
322
- this.cleanupTimers();
323
- });
324
- this._beforeUnloadSetup = true;
325
- }
326
  }
327
 
328
  // 🐛 NEW BUG FIX #2: Método centralizado para limpar timers (previne memory leak)
@@ -478,15 +467,11 @@ class FitnessApp {
478
  }
479
 
480
  showProfileSetup() {
481
- // 🐛 BUG FIX #5: Esconder tela de boas-vindas e app container
482
  const welcomeScreen = document.getElementById('welcomeScreen');
483
- const appContainer = document.getElementById('appContainer');
484
  if (welcomeScreen) {
485
  welcomeScreen.style.display = 'none';
486
  }
487
- if (appContainer) {
488
- appContainer.style.display = 'none';
489
- }
490
 
491
  const setupHTML = `
492
  <div class="profile-setup-screen" id="profileSetup">
@@ -718,25 +703,18 @@ class FitnessApp {
718
  // Remove setup screen
719
  document.getElementById('profileSetup').remove();
720
 
721
- // 🐛 BUG FIX #3: Removido localStorage.setItem('appVisited', 'true') daqui
722
- // A flag será definida quando o usuário clicar em "Começar Agora" na tela de boas-vindas
723
  this.showWelcome();
724
 
725
- // 🐛 BUG FIX #1: Initialize app completamente ANTES de mostrar welcome
726
  this.generatePersonalPlan();
727
  this.setupEventListeners();
728
- this.resetDailyCalories(); // 🔥 FIX: Adicionado - estava faltando
729
- this.updateAllStats(); // 🔥 FIX: Usa função centralizada que chama updateUI, updateWeightDisplay, updateDetailedStats
730
  this.loadAchievements();
 
 
731
  this.setupPWA();
732
-
733
- // 🐛 NEW BUG FIX #2: Cleanup timers quando a página descarrega (caso não tenha sido configurado)
734
- if (!this._beforeUnloadSetup) {
735
- window.addEventListener('beforeunload', () => {
736
- this.cleanupTimers();
737
- });
738
- this._beforeUnloadSetup = true;
739
- }
740
  }
741
 
742
  calculateBMI(weight, height) {
@@ -1717,12 +1695,6 @@ class FitnessApp {
1717
  const welcome = document.getElementById('welcomeScreen');
1718
  const app = document.getElementById('appContainer');
1719
 
1720
- // 🐛 BUG FIX #2: Garantir que o app esteja completamente inicializado
1721
- // Verificar se ainda não foi configurado (primeira vez após criar perfil)
1722
- if (!this._appFullyInitialized) {
1723
- this._appFullyInitialized = true;
1724
- }
1725
-
1726
  welcome.style.animation = 'fadeOut 0.5s ease';
1727
  setTimeout(() => {
1728
  welcome.style.display = 'none';
@@ -1731,12 +1703,6 @@ class FitnessApp {
1731
  }
1732
 
1733
  setupEventListeners() {
1734
- // 🐛 BUG FIX #4: Prevenir configuração duplicada de event listeners
1735
- if (this._eventListenersSetup) {
1736
- console.log('⚠️ Event listeners já configurados, pulando...');
1737
- return;
1738
- }
1739
-
1740
  // Use event delegation for better performance and to handle dynamic elements
1741
  // 🎯 CONSOLIDATED: All click handlers in ONE place to prevent duplicate listeners
1742
 
@@ -1939,10 +1905,6 @@ class FitnessApp {
1939
  this.playCuteSound('click');
1940
  }
1941
  }, true); // Use capture phase to play sound first
1942
-
1943
- // 🐛 BUG FIX #4: Marcar event listeners como configurados
1944
- this._eventListenersSetup = true;
1945
- console.log('✅ Event listeners configurados com sucesso');
1946
  }
1947
 
1948
  navigateTo(view, addToHistory = true) {
 
25
  this.activeTimeouts = new Set();
26
  this.activeVideoHandlers = null;
27
 
 
 
 
 
 
28
  // 🎥 Video and Audio Configuration - Smart detection
29
  // Check if running as PWA (installed app) or has ?source=pwa parameter
30
  const urlParams = new URLSearchParams(window.location.search);
 
308
  this.loadAchievements();
309
  this.setupPWA();
310
 
 
 
 
311
  // 🐛 NEW BUG FIX #2: Cleanup timers quando a página descarrega
312
+ window.addEventListener('beforeunload', () => {
313
+ this.cleanupTimers();
314
+ });
 
 
 
315
  }
316
 
317
  // 🐛 NEW BUG FIX #2: Método centralizado para limpar timers (previne memory leak)
 
467
  }
468
 
469
  showProfileSetup() {
470
+ // 🐛 FIX: Esconde a welcome screen para mostrar o formulário de perfil
471
  const welcomeScreen = document.getElementById('welcomeScreen');
 
472
  if (welcomeScreen) {
473
  welcomeScreen.style.display = 'none';
474
  }
 
 
 
475
 
476
  const setupHTML = `
477
  <div class="profile-setup-screen" id="profileSetup">
 
703
  // Remove setup screen
704
  document.getElementById('profileSetup').remove();
705
 
706
+ // Show welcome
707
+ localStorage.setItem('appVisited', 'true');
708
  this.showWelcome();
709
 
710
+ // Initialize app
711
  this.generatePersonalPlan();
712
  this.setupEventListeners();
713
+ this.updateUI();
 
714
  this.loadAchievements();
715
+ this.updateWeightDisplay();
716
+ this.updateDetailedStats();
717
  this.setupPWA();
 
 
 
 
 
 
 
 
718
  }
719
 
720
  calculateBMI(weight, height) {
 
1695
  const welcome = document.getElementById('welcomeScreen');
1696
  const app = document.getElementById('appContainer');
1697
 
 
 
 
 
 
 
1698
  welcome.style.animation = 'fadeOut 0.5s ease';
1699
  setTimeout(() => {
1700
  welcome.style.display = 'none';
 
1703
  }
1704
 
1705
  setupEventListeners() {
 
 
 
 
 
 
1706
  // Use event delegation for better performance and to handle dynamic elements
1707
  // 🎯 CONSOLIDATED: All click handlers in ONE place to prevent duplicate listeners
1708
 
 
1905
  this.playCuteSound('click');
1906
  }
1907
  }, true); // Use capture phase to play sound first
 
 
 
 
1908
  }
1909
 
1910
  navigateTo(view, addToHistory = true) {
public/app.min.js CHANGED
The diff for this file is too large to render. See raw diff