From d4fd0047cb5617a25f1fd0c11dd7f41697e5c448 Mon Sep 17 00:00:00 2001 From: Dustin Healy Date: Fri, 5 Sep 2025 22:31:06 -0700 Subject: [PATCH] fix: deletion + version updates not working properly --- .../hooks/Prompts/usePromptFileHandling.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/client/src/hooks/Prompts/usePromptFileHandling.ts b/client/src/hooks/Prompts/usePromptFileHandling.ts index 3d03c10661..d88340b00f 100644 --- a/client/src/hooks/Prompts/usePromptFileHandling.ts +++ b/client/src/hooks/Prompts/usePromptFileHandling.ts @@ -38,7 +38,15 @@ export const usePromptFileHandling = (params?: UsePromptFileHandling) => { const [filesLoading, setFilesLoading] = useState(false); const abortControllerRef = useRef(null); - const deleteFileMutation = useDeleteFilesMutation(); + const deleteFileMutation = useDeleteFilesMutation({ + onSuccess: () => { + params?.onFileChange?.(); + }, + onError: (error) => { + logger.error('Error deleting file:', error); + params?.onFileChange?.(); + }, + }); const uploadFile = useUploadFileMutation({ onSuccess: (data) => { @@ -53,7 +61,13 @@ export const usePromptFileHandling = (params?: UsePromptFileHandling) => { filepath: data.filepath, progress: 1, attached: true, - preview: file.preview, + preview: data.filepath || file.preview, // Use filepath for preview if available + filename: data.filename || file.filename, + type: data.type || file.type, + size: data.bytes || file.size, + width: data.width || file.width, + height: data.height || file.height, + source: data.source || file.source, }; } return file; @@ -65,6 +79,9 @@ export const usePromptFileHandling = (params?: UsePromptFileHandling) => { message: 'File uploaded successfully', status: 'success', }); + + // Call the onFileChange callback to trigger save + params?.onFileChange?.(); }, onError: (error, body) => { logger.error('File upload error:', error); @@ -226,9 +243,6 @@ export const usePromptFileHandling = (params?: UsePromptFileHandling) => { return true; // Keep this file }); }); - - // Call the onFileChange callback to trigger save - params?.onFileChange?.(); }, [deleteFileMutation, params?.onFileChange], );