fix(projects): la lista salía vacía — el backend envuelve en {projects}
GET /projects responde { "projects": [...] } (ProjectApiController@index),
pero normalize() solo contemplaba un array o { data } → siempre [].
Ahora normalize acepta {projects}/{data}/array, los tipos de listProjects
y getTemplates reflejan la envoltura real ({projects}/{templates}), y el
fallback offline loguea el motivo en vez de tragarse el error.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -19,8 +19,11 @@ import { RootStackParamList } from '../navigation/types';
|
||||
|
||||
type Props = NativeStackScreenProps<RootStackParamList, 'Projects'>;
|
||||
|
||||
function normalize(res: { data?: Project[] } | Project[]): Project[] {
|
||||
return Array.isArray(res) ? res : res.data ?? [];
|
||||
/** Tolerante con la forma de la respuesta: `{projects}` (actual), `{data}` o array. */
|
||||
function normalize(res: unknown): Project[] {
|
||||
if (Array.isArray(res)) return res as Project[];
|
||||
const obj = (res ?? {}) as { projects?: Project[]; data?: Project[] };
|
||||
return obj.projects ?? obj.data ?? [];
|
||||
}
|
||||
|
||||
export function ProjectsScreen({ navigation }: Props) {
|
||||
@@ -37,7 +40,8 @@ export function ProjectsScreen({ navigation }: Props) {
|
||||
await saveProjectList(list);
|
||||
}
|
||||
setProjects(await getProjects());
|
||||
} catch {
|
||||
} catch (e) {
|
||||
console.warn('No se pudo refrescar /projects, usando datos locales:', e);
|
||||
setProjects(await getProjects()); // fallback offline
|
||||
} finally {
|
||||
setLoading(false);
|
||||
|
||||
Reference in New Issue
Block a user