From db48cd38cda43a3f83dff99967ed6643e4a7a9e5 Mon Sep 17 00:00:00 2001 From: Cristhian Zanforlin Lousa Date: Fri, 4 Jul 2025 17:18:04 -0300 Subject: [PATCH] refactor: Improve async handling and file clearing logic (#8835) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix chat image sent * πŸ› (chat-input.tsx): fix issue where files were not being cleared immediately after sending a message πŸ“ (chat-input.tsx): refactor code to improve readability and maintainability by extracting filesToSend logic into a separate variable * Delete diff_output_ts.txt * ♻️ (chat-input.tsx): refactor code to store and restore files when sending a message to prevent losing files if an error occurs during sending. * βœ… (fileUploadComponent.spec.ts): update timeout values for better test reliability and performance * βœ… (fileUploadComponent.spec.ts): update test assertion to check for the correct attribute value to ensure accurate testing --------- Co-authored-by: Ítalo Johnny Co-authored-by: Gabriel Luiz Freitas Almeida --- .../components/chatView/chatInput/chat-input.tsx | 12 +++++++----- .../chatView/chatInput/components/no-input.tsx | 6 +++--- .../src/modals/IOModal/playground-modal.tsx | 2 +- .../tests/core/unit/fileUploadComponent.spec.ts | 15 ++------------- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/chat-input.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/chat-input.tsx index 435f231b1..08e466b10 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/chat-input.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/chat-input.tsx @@ -166,18 +166,20 @@ export default function ChatInput({ const send = async () => { const storedChatValue = chatValue; + const filesToSend = files + .map((file) => file.path ?? "") + .filter((file) => file !== ""); + const storedFiles = [...files]; + setFiles([]); try { await sendMessage({ repeat: 1, - files: files - .map((file) => file.path ?? "") - .filter((file) => file !== ""), + files: filesToSend, }); } catch (error) { setChatValueStore(storedChatValue); + setFiles(storedFiles); } - - setFiles([]); }; const checkSendingOk = (event: React.KeyboardEvent) => { diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/no-input.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/no-input.tsx index a05add60a..bf690eb16 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/no-input.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatInput/components/no-input.tsx @@ -7,7 +7,7 @@ import { cn } from "../../../../../../utils/utils"; interface NoInputViewProps { isBuilding: boolean; - sendMessage: (args: { repeat: number }) => void; + sendMessage: (args: { repeat: number }) => Promise; stopBuilding: () => void; } @@ -23,8 +23,8 @@ const NoInputView: React.FC = ({