@@ -32,6 +32,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
3232 const [ chatId , setChatId ] = useState < string > ( ) ;
3333 const [ messages , setMessages ] = useState < ChatMessage [ ] > ( [ INITIAL_MESSAGE ] ) ;
3434 const [ userInput , setUserInput ] = useState ( '' ) ;
35+ const [ maxContentSize , setMaxContentSize ] = useState ( 1000 ) ;
3536 const tokens = useTokens ( ) ;
3637
3738 const handleUserInput = ( event : React . ChangeEvent < HTMLInputElement > ) => {
@@ -56,7 +57,7 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
5657 . finally ( ( ) => {
5758 setIsLoading ( false ) ;
5859 } ) ;
59- } , [ chatId , tokens , userInput ] ) ;
60+ } , [ chatId , tokens , userInput , maxContentSize ] ) ;
6061
6162 const keyDown : React . KeyboardEventHandler < HTMLInputElement > = useCallback (
6263 e => {
@@ -71,8 +72,11 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
7172 initChat ( tokens , getSection ( ) , getText ( ) ) . then ( resp => {
7273 const message = resp . response ;
7374 const conversationId = resp . conversationId ;
75+ const maxMessageSize = resp . maxContentSize ;
7476 setMessages ( [ message ] ) ;
77+ setMaxContentSize ( maxMessageSize ) ;
7578 setChatId ( conversationId ) ;
79+ setUserInput ( '' ) ;
7680 } ) ;
7781 } , [ getSection , getText , tokens ] ) ;
7882
@@ -100,22 +104,29 @@ const ChatBox: React.FC<Props> = ({ getSection, getText }) => {
100104 ) ) }
101105 { isLoading && < p > loading...</ p > }
102106 </ div >
103- < input
104- type = "text"
105- disabled = { isLoading }
106- className = { classes [ 'user-input' ] }
107- placeholder = { isLoading ? 'Waiting for response...' : 'Type your message here...' }
108- value = { userInput }
109- onChange = { handleUserInput }
110- onKeyDown = { keyDown }
111- />
112- < div className = { classes [ 'button-container' ] } >
113- < Button disabled = { isLoading } className = { classes [ 'button-send' ] } onClick = { sendMessage } >
114- Send
115- </ Button >
116- < Button className = { classes [ 'button-clean' ] } onClick = { resetChat } >
117- Clean
118- </ Button >
107+ < div className = { classes [ 'control-container' ] } >
108+ < input
109+ type = "text"
110+ disabled = { isLoading }
111+ className = { classes [ 'user-input' ] }
112+ placeholder = { isLoading ? 'Waiting for response...' : 'Type your message here...' }
113+ value = { userInput }
114+ onChange = { handleUserInput }
115+ onKeyDown = { keyDown }
116+ maxLength = { maxContentSize }
117+ />
118+ < div className = { classes [ 'input-count-container' ] } >
119+ < div className = { classes [ 'input-count' ] } > { `${ userInput . length } /${ maxContentSize } ` } </ div >
120+ </ div >
121+
122+ < div className = { classes [ 'button-container' ] } >
123+ < Button disabled = { isLoading } className = { classes [ 'button-send' ] } onClick = { sendMessage } >
124+ Send
125+ </ Button >
126+ < Button className = { classes [ 'button-clean' ] } onClick = { resetChat } >
127+ Clean
128+ </ Button >
129+ </ div >
119130 </ div >
120131 </ div >
121132 ) ;
0 commit comments