From 4fa0e65dd3c50af194c8446183dabf9e5c600b86 Mon Sep 17 00:00:00 2001 From: sean-eskerium Date: Thu, 21 Aug 2025 03:10:43 -0400 Subject: [PATCH] - Fix the optimistic updates on the docs tab. --- .../src/components/project-tasks/DocsTab.tsx | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/archon-ui-main/src/components/project-tasks/DocsTab.tsx b/archon-ui-main/src/components/project-tasks/DocsTab.tsx index 1b30e7cd..fd605c3a 100644 --- a/archon-ui-main/src/components/project-tasks/DocsTab.tsx +++ b/archon-ui-main/src/components/project-tasks/DocsTab.tsx @@ -25,7 +25,7 @@ interface ProjectDoc { created_at: string; updated_at: string; // Content field stores markdown or structured data - content?: any; + content: any; document_type?: string; } @@ -574,9 +574,9 @@ export const DocsTab = ({ const projectDocuments: ProjectDoc[] = project.docs.map((doc: any) => ({ id: doc.id, title: doc.title || 'Untitled Document', - created_at: doc.created_at, - updated_at: doc.updated_at, - content: doc.content, + created_at: doc.created_at || new Date().toISOString(), + updated_at: doc.updated_at || new Date().toISOString(), + content: doc.content || {}, document_type: doc.document_type || 'document' })); @@ -629,19 +629,36 @@ export const DocsTab = ({ }); setSelectedDocument(tempDocument); setShowTemplateModal(false); + setIsSaving(false); // Allow UI to show the temp document try { setIsSaving(true); // Create document via backend API - const newDocument = await projectService.createDocument(project.id, { + const createdDoc = await projectService.createDocument(project.id, { title: template.name, content: template.content, document_type: template.document_type }); - // Force refresh to get the real document from server - await loadProjectDocuments(); + // Ensure the created document has all required fields + const newDocument: ProjectDoc = { + id: createdDoc.id, + title: createdDoc.title || template.name, + created_at: createdDoc.created_at || new Date().toISOString(), + updated_at: createdDoc.updated_at || new Date().toISOString(), + content: createdDoc.content || template.content, + document_type: createdDoc.document_type || template.document_type + }; + + // Replace temp document with real one - same pattern as tasks + setDocuments(prev => { + // Find and replace the temp document + const updated = prev.map(doc => + doc.id === tempDocument.id ? newDocument : doc + ); + return updated; + }); // Select the newly created document setSelectedDocument(newDocument);