From 07e6b137c40860edb899ef77b93c7ba7dd99436b Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 10 Jul 2023 19:45:12 -0300 Subject: [PATCH 1/3] Fixed display prompt showing when there is no template --- .../modals/formModal/chatMessage/index.tsx | 93 ++++++++++--------- 1 file changed, 49 insertions(+), 44 deletions(-) diff --git a/src/frontend/src/modals/formModal/chatMessage/index.tsx b/src/frontend/src/modals/formModal/chatMessage/index.tsx index 6e7457549..93ef22bc2 100644 --- a/src/frontend/src/modals/formModal/chatMessage/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/index.tsx @@ -138,51 +138,56 @@ export default function ChatMessage({ ) : (
- - - {promptOpen - ? template?.split("\n")?.map((line, index) => { - const regex = /{([^}]+)}/g; - let match; - let parts = []; - 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]]} - - ); - } + {template && ( + <> + + + {promptOpen + ? template?.split("\n")?.map((line, index) => { + const regex = /{([^}]+)}/g; + let match; + let parts = []; + 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}

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

{parts}

; + }) + : chat.message[chat.chatKey]} +
+ + )} + {chat.message[chat.chatKey]}
)} From d0be10505550565c7646d7304e4ba2edd8bdbd4f Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 10 Jul 2023 19:48:04 -0300 Subject: [PATCH 2/3] Fixed code area saving when not supposed to --- src/frontend/src/modals/codeAreaModal/index.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/frontend/src/modals/codeAreaModal/index.tsx b/src/frontend/src/modals/codeAreaModal/index.tsx index fc012f6b7..21ef182c3 100644 --- a/src/frontend/src/modals/codeAreaModal/index.tsx +++ b/src/frontend/src/modals/codeAreaModal/index.tsx @@ -5,7 +5,7 @@ import "ace-builds/src-noconflict/mode-python"; import "ace-builds/src-noconflict/theme-github"; import "ace-builds/src-noconflict/theme-twilight"; import { TerminalSquare } from "lucide-react"; -import { useContext, useEffect, useRef, useState } from "react"; +import { useContext, useRef, useState } from "react"; import AceEditor from "react-ace"; import { Button } from "../../components/ui/button"; import { CODE_PROMPT_DIALOG_SUBTITLE } from "../../constants"; @@ -37,9 +37,6 @@ export default function CodeAreaModal({ detail: { error: string; traceback: string }; }>(null); const ref = useRef(); - useEffect(() => { - setValue(code); - }, [code, setValue]); function setModalOpen(x: boolean) { if (x === false) { From 3285aa5cc3eac9a9098c315ce6048d136bd7910b Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Mon, 10 Jul 2023 20:19:38 -0300 Subject: [PATCH 3/3] Fixed scroll glitch on code block --- .../formModal/chatMessage/codeBlock/index.tsx | 8 +- .../modals/formModal/chatMessage/index.tsx | 91 +++++++++++-------- 2 files changed, 56 insertions(+), 43 deletions(-) diff --git a/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx b/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx index c78974a3c..884215ebb 100644 --- a/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/codeBlock/index.tsx @@ -1,5 +1,5 @@ import { IconCheck, IconClipboard, IconDownload } from "@tabler/icons-react"; -import { FC, memo, useState } from "react"; +import { useState } from "react"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark } from "react-syntax-highlighter/dist/cjs/styles/prism"; import { programmingLanguages } from "../../../../utils"; @@ -9,7 +9,7 @@ interface Props { value: string; } -export const CodeBlock: FC = memo(({ language, value }) => { +export function CodeBlock({ language, value }) { const [isCopied, setIsCopied] = useState(false); const copyToClipboard = () => { @@ -63,7 +63,7 @@ export const CodeBlock: FC = memo(({ language, value }) => { = memo(({ language, value }) => { ); -}); +} CodeBlock.displayName = "CodeBlock"; diff --git a/src/frontend/src/modals/formModal/chatMessage/index.tsx b/src/frontend/src/modals/formModal/chatMessage/index.tsx index 93ef22bc2..4e941e278 100644 --- a/src/frontend/src/modals/formModal/chatMessage/index.tsx +++ b/src/frontend/src/modals/formModal/chatMessage/index.tsx @@ -1,6 +1,6 @@ import Convert from "ansi-to-html"; import { ChevronDown } from "lucide-react"; -import { useState } from "react"; +import { useMemo, useState } from "react"; import ReactMarkdown from "react-markdown"; import rehypeMathjax from "rehype-mathjax"; import remarkGfm from "remark-gfm"; @@ -75,47 +75,60 @@ export default function ChatMessage({
- - ▍ - + components={{ + code: ({ + node, + inline, + className, + children, + ...props + }) => { + if (children.length) { + if (children[0] === "▍") { + return ( + + ▍ + + ); + } + + children[0] = (children[0] as string).replace( + "`▍`", + "▍" + ); + } + + const match = /language-(\w+)/.exec( + className || "" ); - } - children[0] = (children[0] as string).replace( - "`▍`", - "▍" - ); - } - - const match = /language-(\w+)/.exec(className || ""); - - return !inline ? ( - - ) : ( - - {children} - - ); - }, - }} - > - {chat.message.toString()} - + return !inline ? ( + + ) : ( + + {children} + + ); + }, + }} + > + {chat.message.toString()} + + ), + [chat.message.toString()] + )}
{chat.files && (