From 7278c1363d540e9a41be4575606b890e30506363 Mon Sep 17 00:00:00 2001 From: javier Date: Tue, 14 Jul 2026 14:08:40 +0200 Subject: [PATCH] =?UTF-8?q?feat(sync):=20prefetch=20del=20cat=C3=A1logo=20?= =?UTF-8?q?de=20plantillas=20para=20trabajar=20offline?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Las plantillas solo llegaban a local en el bundle al abrir un proyecto online. Ahora, al cargar la lista de proyectos con conexión, se prefetchan TODAS las plantillas accesibles (GET /templates, antes sin usar) y se guardan en local, para poder inspeccionar offline aunque el proyecto no se haya abierto todavía. Tolerante a fallo: no bloquea la lista. Co-Authored-By: Claude Opus 4.8 --- src/screens/ProjectsScreen.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/screens/ProjectsScreen.tsx b/src/screens/ProjectsScreen.tsx index 54f8a38..e3cae6a 100644 --- a/src/screens/ProjectsScreen.tsx +++ b/src/screens/ProjectsScreen.tsx @@ -12,7 +12,7 @@ import { import * as api from '../api/endpoints'; import { Project } from '../api/types'; import { useSession } from '../auth/session'; -import { getProjects, saveProjectList, setActiveProjectId } from '../db/repositories'; +import { getProjects, saveProjectList, saveTemplates, setActiveProjectId } from '../db/repositories'; import { isOnline } from '../net/connectivity'; import { runSync } from '../sync/engine'; import { RootStackParamList } from '../navigation/types'; @@ -38,6 +38,15 @@ export function ProjectsScreen({ navigation }: Props) { if (await isOnline()) { const list = normalize(await api.listProjects()); await saveProjectList(list); + // Prefetch del catálogo global de plantillas: así quedan SIEMPRE en + // local y se puede inspeccionar offline aunque el proyecto no se haya + // abierto todavía. No bloquea la lista si /templates falla. + try { + const { templates } = await api.getTemplates(); + await saveTemplates(templates); + } catch (e) { + console.warn('No se pudieron prefetchar las plantillas:', e); + } } setProjects(await getProjects()); } catch (e) {