Skip to content

Commit 82c0b5d

Browse files
committed
Quick UI fix and refactor
1 parent 6259d09 commit 82c0b5d

1 file changed

Lines changed: 3 additions & 27 deletions

File tree

frontend/components/ChatBox.js

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useRef, useEffect, useState, useCallback } from 'react';
1+
import React, { useRef, useEffect } from 'react';
22
import ReactMarkdown from 'react-markdown';
33
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
44
import { oneDark } from 'react-syntax-highlighter/dist/cjs/styles/prism';
@@ -9,32 +9,16 @@ import { faInfoCircle } from '@fortawesome/free-solid-svg-icons';
99
import { Virtuoso } from 'react-virtuoso';
1010
import { CopyToClipboard } from 'react-copy-to-clipboard';
1111
import { FaClipboardCheck } from 'react-icons/fa';
12-
import { AiFillFileAdd } from 'react-icons/ai';
13-
import EditFilesModal from './EditFilesModal';
1412

1513
const encoding = get_encoding("cl100k_base");
1614

17-
18-
19-
// CodeBlock Component
2015
const CodeBlock = React.memo(({ node, inline, className, children }) => {
21-
const [isOpen, setIsOpen] = useState(false);
22-
const handleOpen = () => setIsOpen(true);
23-
const handleClose = () => setIsOpen(false);
24-
2516
const match = /language-(\w+)/.exec(className || '');
2617
const lang = match && match[1] ? match[1] : '';
2718

2819
return !inline && match ? (
2920
<div className='relative bg-zinc-800 rounded overflow-x-scroll'>
30-
<text className='text-sm flex pt-2 pl-2'>{lang}</text>
31-
<button onClick={handleOpen} className='absolute top-2 right-2 text-sm mb-0 mr-10' data-tip data-for='addFileTip'>
32-
<AiFillFileAdd />
33-
</button>
34-
<ReactTooltip id='addFileTip' place="top" effect='solid'>
35-
Add code to file
36-
</ReactTooltip>
37-
<EditFilesModal isOpen={isOpen} handleClose={handleClose} code={String(children)} lang={lang} />
21+
<p className='text-sm flex pt-2 pl-2'>{lang}</p>
3822
<CopyToClipboard className='absolute top-2 right-2 text-sm mb-0' text={String(children)}>
3923
<button >
4024
<FaClipboardCheck data-tip data-for='copyCodeTip' className='text-white' />
@@ -43,7 +27,7 @@ const CodeBlock = React.memo(({ node, inline, className, children }) => {
4327
<ReactTooltip id='copyCodeTip' place="top" effect='solid'>
4428
Copy Code
4529
</ReactTooltip>
46-
<SyntaxHighlighter language={lang} style={oneDark}>
30+
<SyntaxHighlighter language={lang} style={oneDark} className='!mb-0'>
4731
{String(children)}
4832
</SyntaxHighlighter>
4933
</div>
@@ -56,16 +40,11 @@ const Chatbox = ({ messages }) => {
5640
const chatboxRef = useRef(null);
5741
const Row = ({ index, data }) => {
5842
const message = data[index];
59-
60-
// If the message has no text, or if we don't have an encoding (e.g., if the model hasn't been loaded yet),
61-
// then don't render a row
6243
if (!message.text || !encoding) {
6344
return null;
6445
}
6546

66-
// Encode the message text
6747
const tokens = encoding.encode(message.text);
68-
6948
return (
7049
<div className={message.user === 'human' ? "bg-gray-700 text-white p-5" : "bg-gray-600 p-5 text-white"}>
7150
<div className='flex flex-row w-1/2 mx-auto'>
@@ -87,8 +66,6 @@ const Chatbox = ({ messages }) => {
8766
chatboxRef.current.scrollToIndex({ index: messages.length - 1, align: 'end' });
8867
}
8968
}, 100);
90-
91-
// Return a cleanup function that will be called when the component unmounts
9269
return () => {
9370
clearTimeout(timerId);
9471
};
@@ -102,7 +79,6 @@ const Chatbox = ({ messages }) => {
10279
ref={chatboxRef}
10380
data={messages}
10481
itemContent={(index) => Row({ index, data: messages })}
105-
// style={{ height: '400px', width: '500px' }}
10682
/>
10783
</div>
10884
);

0 commit comments

Comments
 (0)