@@ -21,8 +21,8 @@ export interface ChatContextType {
2121 isNewTopic ?: boolean ;
2222 } ) => Promise < void > ;
2323 clearChat : ( ) => void ;
24- keywords : string [ ] ;
25- setKeywords : React . Dispatch < React . SetStateAction < string [ ] > > ;
24+ category : string ;
25+ setCategory : React . Dispatch < React . SetStateAction < string > > ;
2626 isNewTopic : boolean ;
2727 setIsNewTopic : React . Dispatch < React . SetStateAction < boolean > > ;
2828 startKeywordCollection : ( message : string ) => void ;
@@ -35,7 +35,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
3535} ) => {
3636 const [ chatLogs , setChatLogs ] = useState < ChatMessage [ ] > ( [ ] ) ;
3737 const [ isBotTyping , setIsBotTyping ] = useState ( false ) ;
38- const [ keywords , setKeywords ] = useState < string [ ] > ( [ ] ) ;
38+ const [ category , setCategory ] = useState < string > ( '' ) ;
3939 const [ isNewTopic , setIsNewTopic ] = useState ( false ) ;
4040 const currentLogsRef = useRef < ChatMessage [ ] > ( [ ] ) ;
4141 const keywordIntervalRef = useRef < NodeJS . Timeout | null > ( null ) ;
@@ -66,7 +66,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
6666 }
6767
6868 const data = await response . json ( ) ;
69- setKeywords ( data . keywords ) ;
69+ setCategory ( data . category ) ;
7070 } catch ( error ) {
7171 console . error ( 'Error fetching keywords:' , error ) ;
7272 }
@@ -125,7 +125,6 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
125125
126126 // Stop collecting keywords before sending message
127127 stopKeywordCollection ( ) ;
128- const finalKeywords = [ ...keywords ] ;
129128
130129 const newLogs : ChatMessage [ ] = [
131130 ...currentLogsRef . current ,
@@ -154,7 +153,7 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
154153 user_id : user . id ,
155154 message,
156155 is_new_topic : newTopic ,
157- keywords : finalKeywords ,
156+ category ,
158157 } ,
159158 accessToken ,
160159 ( updatedBotMessage ) => {
@@ -180,8 +179,6 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
180179 )
181180 ) ;
182181 setIsBotTyping ( false ) ;
183- // Clear keywords for next message
184- setKeywords ( [ ] ) ;
185182 }
186183 ) ;
187184 } catch ( err ) {
@@ -194,15 +191,14 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
194191 )
195192 ) ;
196193 setIsBotTyping ( false ) ;
197- setKeywords ( [ ] ) ;
198194 }
199195 }
200196 } ;
201197
202198 const clearChat = ( ) => {
203199 setChatLogs ( [ ] ) ;
204200 currentLogsRef . current = [ ] ;
205- setKeywords ( [ ] ) ;
201+ setCategory ( '' ) ;
206202 stopKeywordCollection ( ) ;
207203 } ;
208204
@@ -221,8 +217,8 @@ export const ChatProvider: React.FC<{ children: ReactNode }> = ({
221217 isBotTyping,
222218 handleSend,
223219 clearChat,
224- keywords ,
225- setKeywords ,
220+ category ,
221+ setCategory ,
226222 isNewTopic,
227223 setIsNewTopic,
228224 startKeywordCollection,
0 commit comments