1
1
import { useEffect , useRef , useState } from "react" ;
2
- import { PencilFill } from "react-bootstrap-icons" ;
2
+ import { ChatRightText , PencilFill , Save } from "react-bootstrap-icons" ;
3
3
import { XCircle } from "react-bootstrap-icons" ;
4
4
import { CheckCircle } from "react-bootstrap-icons" ;
5
5
6
- export default function TitleBar ( { current_title, updateTitle} ) {
6
+ export default function TitleBar ( { current_title, updateTitle, current_instruction , updateSystemInstruction } ) {
7
7
const [ title , setTitle ] = useState ( current_title ) ;
8
8
const [ is_editing , toggleEditTitle ] = useState ( false ) ;
9
+ const [ system_instruction , setSystemInstruction ] = useState ( current_instruction || '' ) ;
10
+ const [ is_editing_si , toggleEditSI ] = useState ( false ) ;
9
11
10
12
const inputRef = useRef ( null ) ;
13
+ const systemInstructionDialogRef = useRef ( ) ;
11
14
12
15
function submitUpdateTitle ( ) {
13
16
if ( is_editing && title !== current_title ) {
@@ -16,6 +19,18 @@ export default function TitleBar({current_title, updateTitle}) {
16
19
toggleEditTitle ( false ) ;
17
20
}
18
21
22
+ function submitSystemInstruction ( ) {
23
+ is_editing_si &&
24
+ system_instruction !== current_instruction &&
25
+ updateSystemInstruction ( system_instruction )
26
+
27
+ toggleEditSI ( false )
28
+ }
29
+
30
+ useEffect ( ( ) => {
31
+ setSystemInstruction ( current_instruction ) ;
32
+ } , [ current_instruction ] )
33
+
19
34
useEffect ( ( ) => {
20
35
setTitle ( current_title ) ;
21
36
} , [ current_title ] )
@@ -27,20 +42,42 @@ export default function TitleBar({current_title, updateTitle}) {
27
42
}
28
43
} , [ is_editing ] )
29
44
45
+ useEffect ( ( ) => {
46
+ if ( is_editing_si ) {
47
+ systemInstructionDialogRef . current . showModal ( ) ;
48
+ } else {
49
+ systemInstructionDialogRef . current . close ( ) ;
50
+ }
51
+ } , [ is_editing_si ] )
52
+
30
53
return (
31
54
< div className = "title-bar" >
32
55
{
33
56
is_editing ?
34
- < form onSubmit = { evt => { evt . preventDefault ( ) ; submitUpdateTitle ( ) } } >
57
+ < form className = "edit-mode" onSubmit = { evt => { evt . preventDefault ( ) ; submitUpdateTitle ( ) } } >
35
58
< input className = "edit-title" ref = { inputRef } value = { title } onChange = { evt => setTitle ( evt . target . value ) } />
36
59
< CheckCircle className = "btn clickable" onClick = { submitUpdateTitle } />
37
60
< XCircle className = "btn clickable" onClick = { ( ) => { setTitle ( current_title ) ; toggleEditTitle ( false ) } } />
38
61
</ form > :
39
- < div className = "display-title clickable" onClick = { ( ) => toggleEditTitle ( true ) } >
40
- < div className = "text" > { current_title } </ div >
41
- < PencilFill className = "edit-icon" />
62
+ < div className = "normal-mode" >
63
+ < div className = "display-title clickable" onClick = { ( ) => toggleEditTitle ( true ) } >
64
+ < div className = "text" > { current_title } </ div >
65
+ < PencilFill className = "edit-icon" />
66
+ </ div >
67
+ < ChatRightText className = "icon clickable" title = "Set the system instruction" onClick = { ( ) => toggleEditSI ( true ) } />
68
+ < Save className = "icon clickable" title = "Save history" />
42
69
</ div >
43
70
}
71
+ < dialog className = "system-instruction" ref = { systemInstructionDialogRef } onClose = { ( ) => toggleEditSI ( false ) } >
72
+ < form onSubmit = { evt => { evt . preventDefault ( ) ; submitSystemInstruction ( ) } } >
73
+ < div className = "title" >
74
+ Set your system instruction for this conversation here:
75
+ </ div >
76
+ < input type = "text" placeholder = "You are a helpful assistant." value = { system_instruction } onChange = { evt => setSystemInstruction ( evt . target . value ) } />
77
+ < div className = "btn clickable" onClick = { submitSystemInstruction } > Update System Instruction</ div >
78
+ < div className = "btn clickable" onClick = { ( ) => toggleEditSI ( false ) } > Cancel</ div >
79
+ </ form >
80
+ </ dialog >
44
81
</ div >
45
82
)
46
83
}
0 commit comments