Add comprehensive debugging logs for state restoration troubleshooting
All checks were successful
Build and Push Docker Images / docker (push) Successful in 48s
All checks were successful
Build and Push Docker Images / docker (push) Successful in 48s
This commit is contained in:
parent
cb9c9f8291
commit
e5dced48d2
26
src/App.tsx
26
src/App.tsx
@ -93,8 +93,13 @@ function App() {
|
||||
// Restore offset order state when navigating to calculator page
|
||||
// This handles browser back from Stripe checkout
|
||||
useEffect(() => {
|
||||
console.log('[State Restoration Debug] useEffect triggered');
|
||||
console.log('[State Restoration Debug] currentPage:', currentPage);
|
||||
console.log('[State Restoration Debug] savedState:', savedState);
|
||||
console.log('[State Restoration Debug] savedState?.showOffsetOrder:', savedState?.showOffsetOrder);
|
||||
|
||||
if (currentPage === 'calculator' && savedState && savedState.showOffsetOrder) {
|
||||
console.log('[State Restoration] Restoring offset order state from localStorage');
|
||||
console.log('[State Restoration] ✅ Conditions met - Restoring offset order state from localStorage');
|
||||
console.log('[State Restoration] Offset tons:', savedState.offsetTons);
|
||||
console.log('[State Restoration] Monetary amount:', savedState.monetaryAmount);
|
||||
console.log('[State Restoration] Calculator type:', savedState.calculatorTypeUsed);
|
||||
@ -103,6 +108,17 @@ function App() {
|
||||
setOffsetTons(savedState.offsetTons || 0);
|
||||
setMonetaryAmount(savedState.monetaryAmount);
|
||||
setCalculatorType(savedState.calculatorTypeUsed || 'trip');
|
||||
} else {
|
||||
console.log('[State Restoration] ❌ Conditions NOT met - State will NOT be restored');
|
||||
if (currentPage !== 'calculator') {
|
||||
console.log('[State Restoration] Reason: currentPage is not "calculator"');
|
||||
}
|
||||
if (!savedState) {
|
||||
console.log('[State Restoration] Reason: savedState is null/undefined');
|
||||
}
|
||||
if (savedState && !savedState.showOffsetOrder) {
|
||||
console.log('[State Restoration] Reason: showOffsetOrder is false');
|
||||
}
|
||||
}
|
||||
}, [currentPage, savedState]);
|
||||
|
||||
@ -122,22 +138,26 @@ function App() {
|
||||
};
|
||||
|
||||
const handleOffsetClick = (tons: number, monetaryAmount?: number) => {
|
||||
console.log('[Offset Click Debug] handleOffsetClick called with tons:', tons, 'amount:', monetaryAmount);
|
||||
setOffsetTons(tons);
|
||||
setMonetaryAmount(monetaryAmount);
|
||||
setShowOffsetOrder(true);
|
||||
|
||||
// Save offset state to localStorage for browser back navigation
|
||||
saveState({
|
||||
const stateToSave = {
|
||||
showOffsetOrder: true,
|
||||
offsetTons: tons,
|
||||
monetaryAmount,
|
||||
calculatorTypeUsed: calculatorType,
|
||||
});
|
||||
};
|
||||
console.log('[Offset Click Debug] Saving state to localStorage:', stateToSave);
|
||||
saveState(stateToSave);
|
||||
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
};
|
||||
|
||||
const handleNavigate = (page: 'home' | 'calculator' | 'how-it-works' | 'about' | 'contact') => {
|
||||
console.log('[Navigation Debug] handleNavigate called with page:', page);
|
||||
setCurrentPage(page);
|
||||
setMobileMenuOpen(false);
|
||||
setIsMobileApp(false);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user