@@ -11,18 +11,16 @@ import {
1111} from 'react'
1212import { Flex , Heading , IconButton , ScrollArea , Tooltip } from '@radix-ui/themes'
1313import ContentEditable from 'react-contenteditable'
14- import toast from 'react-hot-toast'
1514import { AiOutlineClear , AiOutlineLoading3Quarters , AiOutlineUnorderedList } from 'react-icons/ai'
1615import { FiSend } from 'react-icons/fi'
16+ import sanitizeHtml from 'sanitize-html'
17+ import { toast } from 'sonner'
1718import ChatContext from './chatContext'
1819import type { Chat , ChatMessage } from './interface'
1920import Message from './Message'
2021
2122import './index.scss'
2223
23- const HTML_REGULAR =
24- / < (? ! i m g | t a b l e | \/ t a b l e | t h e a d | \/ t h e a d | t b o d y | \/ t b o d y | t r | \/ t r | t d | \/ t d | t h | \/ t h | b r | \/ b r ) .* ?> / gi
25-
2624export interface ChatProps { }
2725
2826export interface ChatGPInstance {
@@ -70,8 +68,7 @@ const Chat = (props: ChatProps, ref: any) => {
7068 async ( e : any ) => {
7169 if ( ! isLoading ) {
7270 e . preventDefault ( )
73- const input = textAreaRef . current ?. innerHTML ?. replace ( HTML_REGULAR , '' ) || ''
74-
71+ const input = sanitizeHtml ( textAreaRef . current ?. innerHTML || '' )
7572 if ( input . length < 1 ) {
7673 toast . error ( 'Please type a message to continue.' )
7774 return
@@ -214,7 +211,33 @@ const Chat = (props: ChatProps, ref: any) => {
214211 px = "4"
215212 style = { { backgroundColor : 'var(--gray-a2)' } }
216213 >
217- < Heading size = "4" > { currentChatRef ?. current ?. persona ?. name || 'None' } </ Heading >
214+ < Heading size = "4" > { currentChatRef ?. current ?. persona ?. name || 'No Persona' } </ Heading >
215+ < Flex gap = "2" align = "center" >
216+ < Tooltip content = "Clear History" >
217+ < IconButton
218+ variant = "soft"
219+ color = "gray"
220+ size = "2"
221+ className = "rounded-xl cursor-pointer"
222+ disabled = { isLoading }
223+ onClick = { clearMessages }
224+ >
225+ < AiOutlineClear className = "size-5" />
226+ </ IconButton >
227+ </ Tooltip >
228+ < Tooltip content = "Toggle Sidebar" >
229+ < IconButton
230+ variant = "soft"
231+ color = "gray"
232+ size = "2"
233+ className = "rounded-lg md:hidden cursor-pointer"
234+ disabled = { isLoading }
235+ onClick = { onToggleSidebar }
236+ >
237+ < AiOutlineUnorderedList className = "size-5" />
238+ </ IconButton >
239+ </ Tooltip >
240+ </ Flex >
218241 </ Flex >
219242 < ScrollArea
220243 className = "flex-1 px-4"
@@ -242,7 +265,7 @@ const Chat = (props: ChatProps, ref: any) => {
242265 html = { message }
243266 disabled = { isLoading }
244267 onChange = { ( e ) => {
245- setMessage ( e . target . value . replace ( HTML_REGULAR , '' ) )
268+ setMessage ( sanitizeHtml ( e . target . value ) )
246269 } }
247270 onKeyDown = { ( e ) => {
248271 handleKeypress ( e )
@@ -259,12 +282,12 @@ const Chat = (props: ChatProps, ref: any) => {
259282 justify = "center"
260283 style = { { color : 'var(--accent-11)' } }
261284 >
262- < AiOutlineLoading3Quarters className = "animate-spin size-4 " />
285+ < AiOutlineLoading3Quarters className = "animate-spin size-5 " />
263286 </ Flex >
264287 ) }
265- < Tooltip content = { ' Send Message' } >
288+ < Tooltip content = " Send Message" >
266289 < IconButton
267- variant = "soft "
290+ variant = "surface "
268291 disabled = { isLoading }
269292 color = "gray"
270293 size = "2"
@@ -274,30 +297,6 @@ const Chat = (props: ChatProps, ref: any) => {
274297 < FiSend className = "size-4" />
275298 </ IconButton >
276299 </ Tooltip >
277- < Tooltip content = { 'Clear History' } >
278- < IconButton
279- variant = "soft"
280- color = "gray"
281- size = "2"
282- className = "rounded-xl cursor-pointer"
283- disabled = { isLoading }
284- onClick = { clearMessages }
285- >
286- < AiOutlineClear className = "size-4" />
287- </ IconButton >
288- </ Tooltip >
289- < Tooltip content = { 'Toggle Sidebar' } >
290- < IconButton
291- variant = "soft"
292- color = "gray"
293- size = "2"
294- className = "rounded-xl md:hidden cursor-pointer"
295- disabled = { isLoading }
296- onClick = { onToggleSidebar }
297- >
298- < AiOutlineUnorderedList className = "size-4" />
299- </ IconButton >
300- </ Tooltip >
301300 </ Flex >
302301 </ Flex >
303302 </ div >
0 commit comments