feat(sync): prefetch del catálogo de plantillas para trabajar offline
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user