@@ -309,19 +309,30 @@ export default function NewBatchModal({ open, setOpen, addQuery }) {
309309
310310function ListOfChats ( { } ) {
311311 const [ chats , setChats ] = useState ( [ ] ) ;
312- const [ createNewChat , setCreateNewChat ] = useState ( false ) ;
312+ // set editChat to -1 if you want to create a new chat, set it a specific index in the chats
313+ // array if you want to edit that chat. Set it to null if you are not editing
314+ const [ editChat , setEditChat ] = useState < number | null > ( null ) ;
313315 return (
314316 < >
315317 < DialogTitle >
316- { createNewChat ? 'New Chat' : 'Create Batch of Chat Formatted Prompts' }
318+ { editChat !== null
319+ ? 'New Chat'
320+ : 'Create Batch of Chat Formatted Prompts' }
317321 </ DialogTitle >
318322 < Divider sx = { { my : 1 } } />
319- { createNewChat ? (
323+ { editChat !== null ? (
320324 < NewChatForm
325+ defaultChats = { editChat === - 1 ? [ ] : chats [ editChat ] }
321326 submitChat = { ( chat ) => {
322- console . log ( chat ) ;
323- setChats ( [ ...chats , chat ] ) ;
324- setCreateNewChat ( false ) ;
327+ // If editChat is -1, then we are creating a new chat
328+ if ( editChat === - 1 ) {
329+ setChats ( [ ...chats , chat ] ) ;
330+ } else {
331+ const newChats = [ ...chats ] ;
332+ newChats [ editChat ] = chat ;
333+ setChats ( newChats ) ;
334+ }
335+ setEditChat ( null ) ;
325336 } }
326337 />
327338 ) : (
@@ -342,9 +353,10 @@ function ListOfChats({}) {
342353 </ ListItemContent >
343354 < ButtonGroup >
344355 < Button
345- disabled
346356 variant = "plain"
347- onClick = { ( ) => alert ( 'net yet implemented' ) }
357+ onClick = { ( ) => {
358+ setEditChat ( index ) ;
359+ } }
348360 >
349361 < PencilIcon size = "18px" />
350362 </ Button >
@@ -362,7 +374,7 @@ function ListOfChats({}) {
362374 </ ListItem >
363375 ) ) }
364376 </ List >
365- < Button variant = "soft" onClick = { ( ) => setCreateNewChat ( true ) } >
377+ < Button variant = "soft" onClick = { ( ) => setEditChat ( - 1 ) } >
366378 Add New
367379 </ Button >
368380 { /* <Button onClick={() => setChats([])}>Clear</Button> */ }
0 commit comments