mirror of
https://github.com/coleam00/Archon.git
synced 2025-12-24 02:39:17 -05:00
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.
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}}
|
||||
|
||||
@@ -561,9 +561,9 @@ export const projectService = {
|
||||
/**
|
||||
* Get a specific document with full content
|
||||
*/
|
||||
async getDocument(docId: string): Promise<any> {
|
||||
async getDocument(projectId: string, docId: string): Promise<any> {
|
||||
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<any> {
|
||||
async updateDocument(projectId: string, docId: string, updates: any): Promise<any> {
|
||||
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<void> {
|
||||
async deleteDocument(projectId: string, docId: string): Promise<void> {
|
||||
try {
|
||||
await callAPI<void>(`/api/docs/${docId}`, { method: 'DELETE' });
|
||||
await callAPI<void>(`/api/projects/${projectId}/docs/${docId}`, { method: 'DELETE' });
|
||||
} catch (error) {
|
||||
console.error(`Failed to delete document ${docId}:`, error);
|
||||
throw error;
|
||||
|
||||
Reference in New Issue
Block a user