From 557282cea5948af261481ff9644515fedf434b97 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Tue, 27 Feb 2024 21:50:34 -0300 Subject: [PATCH] Refactor imports and remove console.log statements --- .../newChatView/chatMessage/index.tsx | 68 +++++++++---------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/src/frontend/src/components/newChatView/chatMessage/index.tsx b/src/frontend/src/components/newChatView/chatMessage/index.tsx index 4f6d8e534..7c606679f 100644 --- a/src/frontend/src/components/newChatView/chatMessage/index.tsx +++ b/src/frontend/src/components/newChatView/chatMessage/index.tsx @@ -1,5 +1,5 @@ import Convert from "ansi-to-html"; -import { useEffect, useMemo, useState, useRef } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import Markdown from "react-markdown"; import rehypeMathjax from "rehype-mathjax"; import remarkGfm from "remark-gfm"; @@ -9,17 +9,17 @@ import Robot from "../../../assets/robot.png"; import SanitizedHTMLWrapper from "../../../components/SanitizedHTMLWrapper"; import CodeTabsComponent from "../../../components/codeTabsComponent"; import IconComponent from "../../../components/genericIconComponent"; +import useFlowStore from "../../../stores/flowStore"; import { chatMessagePropsType } from "../../../types/components"; import { classNames } from "../../../utils/utils"; import FileCard from "../fileComponent"; -import useFlowStore from "../../../stores/flowStore"; export default function ChatMessage({ chat, lockChat, lastMessage, updateChat, - setLockChat + setLockChat, }: chatMessagePropsType): JSX.Element { const convert = new Convert({ newline: true }); const [hidden, setHidden] = useState(true); @@ -40,8 +40,6 @@ export default function ChatMessage({ chatMessageRef.current = chatMessage; }, [chatMessage]); - - // The idea now is that chat.stream_url MAY be a URL if we should stream the output of the chat // probably the message is empty when we have a stream_url // what we need is to update the chat_message with the SSE data @@ -70,9 +68,7 @@ export default function ChatMessage({ }); }; - useEffect(() => { - console.log("chatMessage", chatMessage); if (streamUrl && !isStreaming) { setLockChat(true); streamChunks(streamUrl) @@ -92,8 +88,8 @@ export default function ChatMessage({ useEffect(() => { return () => { eventSource.current?.close(); - } - }, []) + }; + }, []); useEffect(() => { const element = document.getElementById("last-chat-message"); @@ -222,7 +218,7 @@ dark:prose-invert" }, ]} activeTab={"0"} - setActiveTab={() => { }} + setActiveTab={() => {}} /> ) : ( @@ -279,33 +275,33 @@ dark:prose-invert" {promptOpen ? template?.split("\n")?.map((line, index) => { - const regex = /{([^}]+)}/g; - let match; - let parts: Array = []; - let lastIndex = 0; - while ((match = regex.exec(line)) !== null) { - // Push text up to the match - if (match.index !== lastIndex) { - parts.push(line.substring(lastIndex, match.index)); - } - // Push div with matched text - if (chat.message[match[1]]) { - parts.push( - - {chat.message[match[1]]} - - ); - } + const regex = /{([^}]+)}/g; + let match; + let parts: Array = []; + let lastIndex = 0; + while ((match = regex.exec(line)) !== null) { + // Push text up to the match + if (match.index !== lastIndex) { + parts.push(line.substring(lastIndex, match.index)); + } + // Push div with matched text + if (chat.message[match[1]]) { + parts.push( + + {chat.message[match[1]]} + + ); + } - // Update last index - lastIndex = regex.lastIndex; - } - // Push text after the last match - if (lastIndex !== line.length) { - parts.push(line.substring(lastIndex)); - } - return

{parts}

; - }) + // Update last index + lastIndex = regex.lastIndex; + } + // Push text after the last match + if (lastIndex !== line.length) { + parts.push(line.substring(lastIndex)); + } + return

{parts}

; + }) : chatMessage}