Refactor imports and remove console.log statements

This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-02-27 21:50:34 -03:00
commit 557282cea5

View file

@ -1,5 +1,5 @@
import Convert from "ansi-to-html"; 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 Markdown from "react-markdown";
import rehypeMathjax from "rehype-mathjax"; import rehypeMathjax from "rehype-mathjax";
import remarkGfm from "remark-gfm"; import remarkGfm from "remark-gfm";
@ -9,17 +9,17 @@ import Robot from "../../../assets/robot.png";
import SanitizedHTMLWrapper from "../../../components/SanitizedHTMLWrapper"; import SanitizedHTMLWrapper from "../../../components/SanitizedHTMLWrapper";
import CodeTabsComponent from "../../../components/codeTabsComponent"; import CodeTabsComponent from "../../../components/codeTabsComponent";
import IconComponent from "../../../components/genericIconComponent"; import IconComponent from "../../../components/genericIconComponent";
import useFlowStore from "../../../stores/flowStore";
import { chatMessagePropsType } from "../../../types/components"; import { chatMessagePropsType } from "../../../types/components";
import { classNames } from "../../../utils/utils"; import { classNames } from "../../../utils/utils";
import FileCard from "../fileComponent"; import FileCard from "../fileComponent";
import useFlowStore from "../../../stores/flowStore";
export default function ChatMessage({ export default function ChatMessage({
chat, chat,
lockChat, lockChat,
lastMessage, lastMessage,
updateChat, updateChat,
setLockChat setLockChat,
}: chatMessagePropsType): JSX.Element { }: chatMessagePropsType): JSX.Element {
const convert = new Convert({ newline: true }); const convert = new Convert({ newline: true });
const [hidden, setHidden] = useState(true); const [hidden, setHidden] = useState(true);
@ -40,8 +40,6 @@ export default function ChatMessage({
chatMessageRef.current = chatMessage; chatMessageRef.current = chatMessage;
}, [chatMessage]); }, [chatMessage]);
// The idea now is that chat.stream_url MAY be a URL if we should stream the output of the chat // 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 // probably the message is empty when we have a stream_url
// what we need is to update the chat_message with the SSE data // what we need is to update the chat_message with the SSE data
@ -70,9 +68,7 @@ export default function ChatMessage({
}); });
}; };
useEffect(() => { useEffect(() => {
console.log("chatMessage", chatMessage);
if (streamUrl && !isStreaming) { if (streamUrl && !isStreaming) {
setLockChat(true); setLockChat(true);
streamChunks(streamUrl) streamChunks(streamUrl)
@ -92,8 +88,8 @@ export default function ChatMessage({
useEffect(() => { useEffect(() => {
return () => { return () => {
eventSource.current?.close(); eventSource.current?.close();
} };
}, []) }, []);
useEffect(() => { useEffect(() => {
const element = document.getElementById("last-chat-message"); const element = document.getElementById("last-chat-message");
@ -222,7 +218,7 @@ dark:prose-invert"
}, },
]} ]}
activeTab={"0"} activeTab={"0"}
setActiveTab={() => { }} setActiveTab={() => {}}
/> />
) : ( ) : (
<code className={className} {...props}> <code className={className} {...props}>
@ -279,33 +275,33 @@ dark:prose-invert"
<span className="prose text-primary word-break-break-word dark:prose-invert"> <span className="prose text-primary word-break-break-word dark:prose-invert">
{promptOpen {promptOpen
? template?.split("\n")?.map((line, index) => { ? template?.split("\n")?.map((line, index) => {
const regex = /{([^}]+)}/g; const regex = /{([^}]+)}/g;
let match; let match;
let parts: Array<JSX.Element | string> = []; let parts: Array<JSX.Element | string> = [];
let lastIndex = 0; let lastIndex = 0;
while ((match = regex.exec(line)) !== null) { while ((match = regex.exec(line)) !== null) {
// Push text up to the match // Push text up to the match
if (match.index !== lastIndex) { if (match.index !== lastIndex) {
parts.push(line.substring(lastIndex, match.index)); parts.push(line.substring(lastIndex, match.index));
} }
// Push div with matched text // Push div with matched text
if (chat.message[match[1]]) { if (chat.message[match[1]]) {
parts.push( parts.push(
<span className="chat-message-highlight"> <span className="chat-message-highlight">
{chat.message[match[1]]} {chat.message[match[1]]}
</span> </span>
); );
} }
// Update last index // Update last index
lastIndex = regex.lastIndex; lastIndex = regex.lastIndex;
} }
// Push text after the last match // Push text after the last match
if (lastIndex !== line.length) { if (lastIndex !== line.length) {
parts.push(line.substring(lastIndex)); parts.push(line.substring(lastIndex));
} }
return <p>{parts}</p>; return <p>{parts}</p>;
}) })
: chatMessage} : chatMessage}
</span> </span>
</> </>