Skip to content

Commit fb34f75

Browse files
chatmode switch mode fix
1 parent aaebdcb commit fb34f75

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

frontend/src/components/ChatBot/Chatbot.tsx

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,15 @@ const Chatbot: FC<ChatbotProps> = (props) => {
269269
console.error(`API call failed for mode ${mode}:`, result.reason);
270270
setListMessages((prev) =>
271271
prev.map((msg) =>
272-
(msg.id === chatbotMessageId
273-
? {
274-
...msg,
275-
modes: {
276-
...msg.modes,
277-
[mode]: { message: 'Failed to fetch response for this mode.', error: result.reason },
278-
},
279-
}
280-
: msg)
272+
(msg.id === chatbotMessageId
273+
? {
274+
...msg,
275+
modes: {
276+
...msg.modes,
277+
[mode]: { message: 'Failed to fetch response for this mode.', error: result.reason },
278+
},
279+
}
280+
: msg)
281281
)
282282
);
283283
}
@@ -290,19 +290,19 @@ const Chatbot: FC<ChatbotProps> = (props) => {
290290
if (error instanceof Error) {
291291
setListMessages((prev) =>
292292
prev.map((msg) =>
293-
(msg.id === chatbotMessageId
294-
? {
295-
...msg,
296-
isLoading: false,
297-
isTyping: false,
298-
modes: {
299-
[chatModes[0]]: {
300-
message: 'An error occurred while processing your request.',
301-
error: error.message,
302-
},
303-
},
304-
}
305-
: msg)
293+
(msg.id === chatbotMessageId
294+
? {
295+
...msg,
296+
isLoading: false,
297+
isTyping: false,
298+
modes: {
299+
[chatModes[0]]: {
300+
message: 'An error occurred while processing your request.',
301+
error: error.message,
302+
},
303+
},
304+
}
305+
: msg)
306306
)
307307
);
308308
}
@@ -391,7 +391,7 @@ const Chatbot: FC<ChatbotProps> = (props) => {
391391
setMetricContext(currentMode.metric_contexts ?? '');
392392
setMetricAnswer(currentMode.metric_answer ?? '');
393393
setActiveChat(chat);
394-
if (previousActiveChat != null && chat.id != previousActiveChat?.id) {
394+
if ((previousActiveChat != null && chat.id != previousActiveChat?.id) || (previousActiveChat != null && chat.currentMode != previousActiveChat.currentMode)) {
395395
setNodes([]);
396396
setChunks([]);
397397
setInfoEntities([]);
@@ -450,14 +450,12 @@ const Chatbot: FC<ChatbotProps> = (props) => {
450450
<Widget
451451
header=''
452452
isElevated={true}
453-
className={`p-4 self-start ${isFullScreen ? 'max-w-[55%]' : ''} ${
454-
chat.user === 'chatbot' ? 'n-bg-palette-neutral-bg-strong' : 'n-bg-palette-primary-bg-weak'
455-
}`}
453+
className={`p-4 self-start ${isFullScreen ? 'max-w-[55%]' : ''} ${chat.user === 'chatbot' ? 'n-bg-palette-neutral-bg-strong' : 'n-bg-palette-primary-bg-weak'
454+
}`}
456455
>
457456
<div
458-
className={`${
459-
chat.isLoading && index === listMessages.length - 1 && chat.user === 'chatbot' ? 'loader' : ''
460-
}`}
457+
className={`${chat.isLoading && index === listMessages.length - 1 && chat.user === 'chatbot' ? 'loader' : ''
458+
}`}
461459
>
462460
<ReactMarkdown className={!isFullScreen ? 'max-w-[250px]' : ''}>
463461
{chat.modes[chat.currentMode]?.message || ''}
@@ -541,9 +539,8 @@ const Chatbot: FC<ChatbotProps> = (props) => {
541539
<div className='n-bg-palette-neutral-bg-weak flex gap-2.5 bottom-0 p-2.5 w-full'>
542540
<form onSubmit={handleSubmit} className={`flex gap-2.5 w-full ${!isFullScreen ? 'justify-between' : ''}`}>
543541
<TextInput
544-
className={`n-bg-palette-neutral-bg-default flex-grow-7 ${
545-
isFullScreen ? 'w-[calc(100%-105px)]' : 'w-[70%]'
546-
}`}
542+
className={`n-bg-palette-neutral-bg-default flex-grow-7 ${isFullScreen ? 'w-[calc(100%-105px)]' : 'w-[70%]'
543+
}`}
547544
aria-label='chatbot-input'
548545
type='text'
549546
value={inputMessage}

0 commit comments

Comments
 (0)