From 61f975d32d68456737735faef003b0e9f5fbabe1 Mon Sep 17 00:00:00 2001 From: cristhianzl Date: Wed, 4 Sep 2024 17:37:02 -0300 Subject: [PATCH] feat: Refactor chatMessage component for improved readability and performance --- .../components/chatView/chatMessage/index.tsx | 51 ++++++++----------- 1 file changed, 20 insertions(+), 31 deletions(-) diff --git a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx index e1739be6196..ad1421661c8 100644 --- a/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx +++ b/src/frontend/src/modals/IOModal/components/chatView/chatMessage/index.tsx @@ -113,18 +113,16 @@ export default function ChatMessage({ } }, [lastMessage]); + const decodedMessage = decodeURIComponent(chatMessage ?? ""); + const isEmpty = decodedMessage?.trim() === ""; + return ( <> -
+
{useMemo( () => - chatMessage === "" && lockChat ? ( + isEmpty && lockChat ? ( - {chatMessage === "" && !chat.stream_url + {isEmpty && !chat.stream_url ? EMPTY_OUTPUT_SEND_MESSAGE : chatMessage} @@ -281,18 +279,13 @@ export default function ChatMessage({ Display Prompt {promptOpen @@ -324,25 +317,21 @@ export default function ChatMessage({ } return

{parts}

; }) - : chatMessage === "" + : isEmpty ? EMPTY_INPUT_SEND_MESSAGE : chatMessage}
) : (
- - {chatMessage === "" ? EMPTY_INPUT_SEND_MESSAGE : chatMessage} - + {isEmpty ? EMPTY_INPUT_SEND_MESSAGE : decodedMessage} +
{chat.files && (
{chat.files.map((file, index) => { @@ -362,7 +351,7 @@ export default function ChatMessage({
)}
-
+
); }