mirror of
https://github.com/coleam00/Archon.git
synced 2026-01-07 15:18:14 -05:00
- Fix the optimistic updates on the docs tab.
This commit is contained in:
@@ -25,7 +25,7 @@ interface ProjectDoc {
|
|||||||
created_at: string;
|
created_at: string;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
// Content field stores markdown or structured data
|
// Content field stores markdown or structured data
|
||||||
content?: any;
|
content: any;
|
||||||
document_type?: string;
|
document_type?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -574,9 +574,9 @@ export const DocsTab = ({
|
|||||||
const projectDocuments: ProjectDoc[] = project.docs.map((doc: any) => ({
|
const projectDocuments: ProjectDoc[] = project.docs.map((doc: any) => ({
|
||||||
id: doc.id,
|
id: doc.id,
|
||||||
title: doc.title || 'Untitled Document',
|
title: doc.title || 'Untitled Document',
|
||||||
created_at: doc.created_at,
|
created_at: doc.created_at || new Date().toISOString(),
|
||||||
updated_at: doc.updated_at,
|
updated_at: doc.updated_at || new Date().toISOString(),
|
||||||
content: doc.content,
|
content: doc.content || {},
|
||||||
document_type: doc.document_type || 'document'
|
document_type: doc.document_type || 'document'
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -629,19 +629,36 @@ export const DocsTab = ({
|
|||||||
});
|
});
|
||||||
setSelectedDocument(tempDocument);
|
setSelectedDocument(tempDocument);
|
||||||
setShowTemplateModal(false);
|
setShowTemplateModal(false);
|
||||||
|
setIsSaving(false); // Allow UI to show the temp document
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setIsSaving(true);
|
setIsSaving(true);
|
||||||
|
|
||||||
// Create document via backend API
|
// Create document via backend API
|
||||||
const newDocument = await projectService.createDocument(project.id, {
|
const createdDoc = await projectService.createDocument(project.id, {
|
||||||
title: template.name,
|
title: template.name,
|
||||||
content: template.content,
|
content: template.content,
|
||||||
document_type: template.document_type
|
document_type: template.document_type
|
||||||
});
|
});
|
||||||
|
|
||||||
// Force refresh to get the real document from server
|
// Ensure the created document has all required fields
|
||||||
await loadProjectDocuments();
|
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
|
// Select the newly created document
|
||||||
setSelectedDocument(newDocument);
|
setSelectedDocument(newDocument);
|
||||||
|
|||||||
Reference in New Issue
Block a user