fix: robust mobile suspend and auth recovery
This commit is contained in:
@ -10,19 +10,38 @@ export const useShuttleStore = defineStore('shuttle', () => {
|
||||
const error = ref<string | null>(null)
|
||||
const filters = ref<ShuttleFilters>({})
|
||||
|
||||
async function loadShuttles(newFilters?: ShuttleFilters) {
|
||||
isLoading.value = true
|
||||
// Safety: nunca más de 12s cargando (protección contra thread congelado por OS al apagar pantalla)
|
||||
let _safetyTimer: ReturnType<typeof setTimeout> | null = null
|
||||
function _startSafetyTimer() {
|
||||
_clearSafetyTimer()
|
||||
_safetyTimer = setTimeout(() => {
|
||||
if (isLoading.value) {
|
||||
console.warn('SIBU | shuttleStore: safety timeout — reseteando isLoading')
|
||||
isLoading.value = false
|
||||
}
|
||||
}, 12000)
|
||||
}
|
||||
function _clearSafetyTimer() {
|
||||
if (_safetyTimer) { clearTimeout(_safetyTimer); _safetyTimer = null }
|
||||
}
|
||||
|
||||
async function loadShuttles(newFilters?: ShuttleFilters, isBackground = false) {
|
||||
if (!isBackground) isLoading.value = true
|
||||
error.value = null
|
||||
if (newFilters) {
|
||||
filters.value = newFilters
|
||||
}
|
||||
if (!isBackground) _startSafetyTimer()
|
||||
try {
|
||||
shuttles.value = await shuttlesService.getAllShuttles(filters.value)
|
||||
} catch (e) {
|
||||
error.value = e instanceof Error ? e.message : 'Failed to load shuttles'
|
||||
console.error('Error loading shuttles:', e)
|
||||
} finally {
|
||||
isLoading.value = false
|
||||
if (!isBackground) {
|
||||
_clearSafetyTimer()
|
||||
isLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user