From 533b72c7ebf940e4c60fa192049929ca903bcf96 Mon Sep 17 00:00:00 2001 From: igorrCarvalho Date: Wed, 5 Jun 2024 20:49:06 -0300 Subject: [PATCH] Fix: user can send more than one file with the same name --- .../chatView/chatInput/hooks/use-handle-file-change.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx index 2de36397c..748ca7fe5 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/hooks/use-handle-file-change.tsx @@ -5,9 +5,10 @@ export const useHandleFileChange = (setFiles, currentFlowId) => { const handleFileChange = async ( event: React.ChangeEvent, ) => { - const file = event.target.files?.[0]; + const fileInput = event.target; + const file = fileInput.files?.[0]; if (file) { - const uid = new ShortUniqueId({ length: 3 }); + const uid = new ShortUniqueId({ length: 10 }); // Increase the length to ensure uniqueness const id = uid(); const type = file.type.split("/")[0]; const blob = file; @@ -19,6 +20,9 @@ export const useHandleFileChange = (setFiles, currentFlowId) => { useFileUpload(blob, currentFlowId, setFiles, id); } + + // Clear the file input value to ensure the change event is triggered even for the same file + fileInput.value = ""; }; return {