@@ -18,7 +18,7 @@ import React, { useState, useEffect } from "react";
1818import config from "./config" ;
1919import { APIService } from "../../constants/APIConstant" ;
2020import MessageParser , { ChatMessage } from "./MessageParser" ;
21- import ActionProvider from "./ActionProvider" ;
21+ import ActionProvider from "./ActionProvider" ;
2222import Chatbot , { createChatBotMessage } from "react-chatbot-kit" ;
2323import { Row , Col } from "antd" ;
2424import { Space } from "antd" ;
@@ -77,8 +77,6 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
7777 messages : [ ] ,
7878 } ) ;
7979
80-
81-
8280 const headerText = ( ) : JSX . Element => {
8381 return (
8482 < div
@@ -134,7 +132,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
134132 chatHistory = res . body ?. chat_history ;
135133 setChatbotState ( ( prev ) => ( {
136134 ...prev ,
137- messages : chatHistory . map ( msg => ( {
135+ messages : chatHistory . map ( ( msg ) => ( {
138136 role : msg . role ,
139137 content : msg . content ,
140138 id : msg . id ,
@@ -171,24 +169,24 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
171169 ) ,
172170 customButtons : (
173171 < button
174- className = "expand-chatbot-btn"
175- style = { { position : "absolute" , top : 10 , right : 10 , zIndex : 1100 } }
176- onClick = { ( ) => setExpanded ( ( prev ) => ! prev ) }
177- aria-label = { expanded ? "Collapse Chatbot" : "Expand Chatbot" }
178- >
179- ⤢
180- </ button >
172+ className = "expand-chatbot-btn"
173+ style = { { position : "absolute" , top : 10 , right : 10 , zIndex : 1100 } }
174+ onClick = { ( ) => setExpanded ( ( prev ) => ! prev ) }
175+ aria-label = { expanded ? "Collapse Chatbot" : "Expand Chatbot" }
176+ >
177+ ⤢
178+ </ button >
181179 ) ,
182180 } ,
183181 state : chatbotState ,
184182 } ;
185183
186184 // Convert ChatMessage[] to IMessage[] for UI
187185 const chatMessagesToIMessages = ( messages : ChatMessage [ ] ) : IMessage [ ] =>
188- messages . map ( msg => ( {
186+ messages . map ( ( msg ) => ( {
189187 id : msg . id ,
190188 message : msg . content ,
191- type : msg . role === "assistant" ? "bot" : "user"
189+ type : msg . role === "assistant" ? "bot" : "user" ,
192190 } ) ) ;
193191
194192 // Dynamic initialMessages state
@@ -199,15 +197,13 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
199197 const history = await fetchChatHistoryFromBackend ( ) ; // returns ChatMessage[]
200198 setInitialMessages (
201199 history . length > 0
202- ? history . map ( msg =>
203- createChatBotMessage ( msg . content , { } )
204- )
200+ ? history . map ( ( msg ) => createChatBotMessage ( msg . content , { } ) )
205201 : [
206202 createChatBotMessage (
207203 `Hi, Welcome to crAPI! I'm CrapBot, and I'm here to be exploited.` ,
208- { }
204+ { } ,
209205 ) ,
210- ]
206+ ] ,
211207 ) ;
212208 }
213209 fetchHistory ( ) ;
@@ -224,7 +220,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
224220 message : string ;
225221 type : string ; // required
226222 }
227-
223+
228224 // Remount Chatbot only on clear, reset, or init
229225 const [ chatbotInstanceKey , setChatbotInstanceKey ] = useState ( 0 ) ;
230226
@@ -263,7 +259,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
263259 // Save messages to backend and re-fetch
264260 const saveMessages = ( messages : IMessage [ ] ) : void => {
265261 // Update UI state immediately (optimistic UI)
266- setChatbotState ( prev => ( {
262+ setChatbotState ( ( prev ) => ( {
267263 ...prev ,
268264 messages : iMessageToChatHistory ( messages ) ,
269265 } ) ) ;
@@ -294,7 +290,7 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
294290
295291 // Convert IMessage[] (UI) to ChatMessage[] (backend)
296292 const iMessageToChatHistory = ( messages : IMessage [ ] ) : ChatMessage [ ] =>
297- messages . map ( msg => ( {
293+ messages . map ( ( msg ) => ( {
298294 role : msg . type === "bot" ? "assistant" : "user" ,
299295 content : msg . message ,
300296 id : msg . id ,
@@ -314,11 +310,11 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
314310 . set ( "Authorization" , `Bearer ${ props . accessToken } ` )
315311 . send ( { chat_history : [ ] } ) ;
316312 const latestHistory = await fetchChatHistoryFromBackend ( ) ;
317- setChatbotState ( prev => ( {
313+ setChatbotState ( ( prev ) => ( {
318314 ...prev ,
319315 messages : latestHistory ,
320316 } ) ) ;
321- setChatbotInstanceKey ( prev => prev + 1 ) ;
317+ setChatbotInstanceKey ( ( prev ) => prev + 1 ) ;
322318 } catch ( err ) {
323319 console . error ( "Failed to clear chat history on backend" , err ) ;
324320 }
@@ -333,21 +329,20 @@ const ChatBotComponent: React.FC<ChatBotComponentProps> = (props) => {
333329 . set ( "Authorization" , `Bearer ${ props . accessToken } ` )
334330 . send ( { chat_history : [ ] } ) ;
335331 const latestHistory = await fetchChatHistoryFromBackend ( ) ;
336- setChatbotState ( prev => ( {
332+ setChatbotState ( ( prev ) => ( {
337333 ...prev ,
338334 messages : latestHistory ,
339335 } ) ) ;
340- setChatbotInstanceKey ( prev => prev + 1 ) ;
336+ setChatbotInstanceKey ( ( prev ) => prev + 1 ) ;
341337 } catch ( err ) {
342338 console . error ( "Failed to reset chat history on backend" , err ) ;
343339 }
344340 } ;
345341
346-
347342 return (
348343 < Row >
349344 < Col xs = { 10 } >
350- < div className = { `app-chatbot-container${ expanded ? ' expanded' : '' } ` } >
345+ < div className = { `app-chatbot-container${ expanded ? " expanded" : "" } ` } >
351346 < div style = { { maxWidth : "100%" , maxHeight : "100%" } } >
352347 { /* Chatbot loads chat history from backend and renders it on UI load */ }
353348 { showBot && initialMessages === null && < div > Loading chat...</ div > }
0 commit comments