From d890180f91cfcf39b04aad53729c7eee26f4f5f9 Mon Sep 17 00:00:00 2001 From: Rasmus Widing Date: Mon, 18 Aug 2025 13:04:53 +0300 Subject: [PATCH] Fix document deletion persistence issue (#278) - Fixed projectService methods to include project_id parameter in API calls - Updated deleteDocument() to use correct endpoint: /api/projects/{projectId}/docs/{docId} - Updated getDocument() and updateDocument() to use correct endpoints with project_id - Modified DocsTab component to call backend API when deleting documents - Documents now properly persist deletion after page refresh The issue was that document deletion was only happening in UI state and never reached the backend. The service methods were using incorrect API endpoints that didn't include the required project_id parameter. --- .../src/components/project-tasks/DocsTab.tsx | 6 +++++- archon-ui-main/src/services/projectService.ts | 12 ++++++------ 2 files changed, 11 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 add2ca56..87e6fa5c 100644 --- a/archon-ui-main/src/components/project-tasks/DocsTab.tsx +++ b/archon-ui-main/src/components/project-tasks/DocsTab.tsx @@ -939,13 +939,17 @@ export const DocsTab = ({ onSelect={setSelectedDocument} onDelete={async (docId) => { try { - // Remove from local state + // Call API to delete from database first + await projectService.deleteDocument(project.id, docId); + + // Then remove from local state setDocuments(prev => prev.filter(d => d.id !== docId)); if (selectedDocument?.id === docId) { setSelectedDocument(documents.find(d => d.id !== docId) || null); } showToast('Document deleted', 'success'); } catch (error) { + console.error('Failed to delete document:', error); showToast('Failed to delete document', 'error'); } }} diff --git a/archon-ui-main/src/services/projectService.ts b/archon-ui-main/src/services/projectService.ts index 4e11378b..f03a9e26 100644 --- a/archon-ui-main/src/services/projectService.ts +++ b/archon-ui-main/src/services/projectService.ts @@ -561,9 +561,9 @@ export const projectService = { /** * Get a specific document with full content */ - async getDocument(docId: string): Promise { + async getDocument(projectId: string, docId: string): Promise { try { - const response = await callAPI<{document: any}>(`/api/docs/${docId}`); + const response = await callAPI<{document: any}>(`/api/projects/${projectId}/docs/${docId}`); return response.document; } catch (error) { console.error(`Failed to get document ${docId}:`, error); @@ -590,9 +590,9 @@ export const projectService = { /** * Update an existing document */ - async updateDocument(docId: string, updates: any): Promise { + async updateDocument(projectId: string, docId: string, updates: any): Promise { try { - const response = await callAPI<{document: any}>(`/api/docs/${docId}`, { + const response = await callAPI<{document: any}>(`/api/projects/${projectId}/docs/${docId}`, { method: 'PUT', body: JSON.stringify(updates) }); @@ -606,9 +606,9 @@ export const projectService = { /** * Delete a document */ - async deleteDocument(docId: string): Promise { + async deleteDocument(projectId: string, docId: string): Promise { try { - await callAPI(`/api/docs/${docId}`, { method: 'DELETE' }); + await callAPI(`/api/projects/${projectId}/docs/${docId}`, { method: 'DELETE' }); } catch (error) { console.error(`Failed to delete document ${docId}:`, error); throw error;