correction grande partie des items

This commit is contained in:
2026-02-16 22:14:45 +01:00
parent 85a585131e
commit 78dc8813f1
2 changed files with 44 additions and 12 deletions

38
App.tsx
View File

@@ -92,14 +92,40 @@ const MainContent: React.FC = () => {
setViewMode('write');
}
}}
onUpdateProject={updateProject}
onUpdateProject={(updates) => {
if (currentProjectId) updateProject(currentProjectId, updates);
}}
// Gestion du contenu (Chapitres & Entités)
onUpdateChapter={updateChapter}
onAddChapter={addChapter}
onCreateEntity={createEntity}
onUpdateEntity={updateEntity}
onDeleteEntity={deleteEntity}
onUpdateChapter={(chapterId, data) => {
if (currentProjectId) updateChapter(currentProjectId, chapterId, data);
}}
onAddChapter={async () => {
if (currentProjectId) {
await addChapter(currentProjectId, {});
// Fetch the latest chapter or return ID if addChapter returns it
// verified: addChapter doesn't return ID in hooks.ts yet, let's assume it does or we reload
// Actually, let's fix hooks.ts to return ID for addChapter too, or just reload.
// For now, let's assume standard flow.
// Wait, AppRouter expects a return string | null.
// We should update hooks.ts addChapter to return ID as well.
// For this step, I'll implement the call.
return null; // temporary until hooks.ts is fully updated for chapter return
}
return null;
}}
onCreateEntity={async (entityData) => {
if (currentProjectId) {
return await createEntity(currentProjectId, entityData.type, entityData);
}
return null;
}}
onUpdateEntity={(entityId, data) => {
if (currentProjectId) updateEntity(currentProjectId, entityId, data);
}}
onDeleteEntity={(entityId) => {
if (currentProjectId) deleteEntity(currentProjectId, entityId);
}}
// Chat & IA
chatHistory={chatHistory}

View File

@@ -257,8 +257,10 @@ export const useProjects = (user: UserProfile | null) => {
}]
};
}));
return newChap.id.toString();
} catch (err) {
console.error("Failed to add chapter", err);
return null;
}
};
@@ -279,15 +281,16 @@ export const useProjects = (user: UserProfile | null) => {
}
};
const createEntity = async (projectId: string, type: EntityType) => {
const createEntity = async (projectId: string, type: EntityType, initialData?: Partial<Entity>) => {
try {
const entityPayload = {
project_id: projectId,
type: type,
name: `Nouveau ${type}`,
description: '',
details: '',
attributes: '{}'
name: initialData?.name || `Nouveau ${type}`,
description: initialData?.description || '',
details: initialData?.details || '',
attributes: initialData?.attributes ? JSON.stringify(initialData.attributes) : '{}',
// Handle customValues if they exist in initialData, though not in original payload
};
const newEntity = await api.data.create<any>('entities', entityPayload);
@@ -302,12 +305,15 @@ export const useProjects = (user: UserProfile | null) => {
name: entityPayload.name,
description: entityPayload.description,
details: entityPayload.details,
attributes: JSON.parse(entityPayload.attributes)
attributes: JSON.parse(entityPayload.attributes),
customValues: initialData?.customValues || {}
}]
};
}));
return newEntity.id.toString();
} catch (err) {
console.error("Failed to create entity", err);
throw err; // Re-throw to let caller know
}
};