fix(wizard): cache geo singleton, feedback carga, debounce draft
geo_paraguay_full.json se cargaba dos veces sin cache compartido. Módulo lib/geo-cache.ts singleton: un fetch para toda la sesión. Feedback visual mientras carga (disabled + placeholder) y si falla (mensaje + texto libre). debounce 500ms en saveDraft para no escribir en localStorage en cada keystroke. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
16
lib/geo-cache.ts
Normal file
16
lib/geo-cache.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
// departamento → ciudad → barrios[]
|
||||
export type GeoData = Record<string, Record<string, string[]>>
|
||||
|
||||
let geoData: GeoData | null = null
|
||||
let geoPromise: Promise<GeoData> | null = null
|
||||
|
||||
export async function getGeoData(): Promise<GeoData> {
|
||||
if (geoData) return geoData
|
||||
if (!geoPromise) {
|
||||
geoPromise = fetch('/data/geo_paraguay_full.json')
|
||||
.then((r) => r.json())
|
||||
.then((data: GeoData) => { geoData = data; return data })
|
||||
.catch((err) => { geoPromise = null; throw err })
|
||||
}
|
||||
return geoPromise
|
||||
}
|
||||
Reference in New Issue
Block a user