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>
17 lines
524 B
TypeScript
17 lines
524 B
TypeScript
// 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
|
|
}
|