fix: implement global app-refocus listener and data recovery pattern in critical views to prevent infinite loading after app suspension

This commit is contained in:
2026-03-03 15:04:16 -05:00
parent cfe9286fcb
commit df0a4397f6
6 changed files with 96 additions and 12 deletions

View File

@ -129,14 +129,27 @@ function closePromoModal() {
selectedPromo.value = null;
}
// Map initialization & Lifecycle
onMounted(async () => {
analyticsService.logEvent({ event_name: 'screen_view', properties: { screen_name: 'Map' } })
async function fetchData() {
await Promise.all([
routeStore.loadRoutes(),
couponStore.loadCoupons({ active_only: true })
]);
updateActiveUnits();
}
function handleRefocus() {
fetchData();
if (map.value) {
google.maps.event.trigger(map.value, 'resize');
}
}
// Map initialization & Lifecycle
onMounted(async () => {
analyticsService.logEvent({ event_name: 'screen_view', properties: { screen_name: 'Map' } })
window.addEventListener('app-refocus', handleRefocus);
await fetchData();
const queryRouteId = router.currentRoute.value.query.routeId as string;
if (queryRouteId && queryRouteId !== routeStore.selectedRouteId) {
@ -158,7 +171,6 @@ onMounted(async () => {
}
unitFetchInterval.value = setInterval(updateActiveUnits, 15000);
updateActiveUnits();
startCarousel();
// 🛰️ RESIZE FIX: Trigger map resize when app becomes visible again
@ -169,7 +181,7 @@ onUnmounted(() => {
if (unitFetchInterval.value) clearInterval(unitFetchInterval.value);
if (carouselTimer.value) clearInterval(carouselTimer.value);
document.removeEventListener('visibilitychange', handleVisibilityChange);
// NOTA: No llamamos a clearMapMarkers() para mantener la ruta si el usuario vuelve
window.removeEventListener('app-refocus', handleRefocus);
});
function handleVisibilityChange() {