@@ -629,6 +629,8 @@ export class ChatWidgetCore {
629629 ) ;
630630 if ( newChatButton ) {
631631 newChatButton . addEventListener ( 'click' , ( ) => this . startNewChat ( ) ) ;
632+ // Set initial disabled state
633+ this . updateNewChatButtonState ( ) ;
632634 }
633635 }
634636
@@ -902,6 +904,7 @@ export class ChatWidgetCore {
902904 }
903905 this . abortController = new AbortController ( ) ;
904906 this . historyPanel . updateDisabledState ( ) ;
907+ this . updateNewChatButtonState ( ) ;
905908
906909 try {
907910 // Create FormData for the request
@@ -1025,6 +1028,7 @@ export class ChatWidgetCore {
10251028 // Reset controller once streaming is done
10261029 this . abortController = null ;
10271030 this . historyPanel . updateDisabledState ( ) ;
1031+ this . updateNewChatButtonState ( ) ;
10281032 break ;
10291033 }
10301034
@@ -1050,15 +1054,18 @@ export class ChatWidgetCore {
10501054 }
10511055 this . abortController = null ;
10521056 this . historyPanel . updateDisabledState ( ) ;
1057+ this . updateNewChatButtonState ( ) ;
10531058 }
10541059 } catch ( error ) {
10551060 console . error ( 'Error sending message to API:' , error ) ;
10561061 if ( this . abortController ?. signal . aborted ) {
10571062 this . abortController = null ;
10581063 this . historyPanel . updateDisabledState ( ) ;
1064+ this . updateNewChatButtonState ( ) ;
10591065 } else {
10601066 this . abortController = null ;
10611067 this . historyPanel . updateDisabledState ( ) ;
1068+ this . updateNewChatButtonState ( ) ;
10621069 // Add an error message to the chat
10631070 this . addBotMessage (
10641071 'Sorry, there was an error processing your message. Please try again later.'
@@ -1701,4 +1708,13 @@ export class ChatWidgetCore {
17011708 }
17021709 } ) ;
17031710 }
1711+
1712+ private updateNewChatButtonState ( ) : void {
1713+ const newChatButton = this . widgetElement ?. querySelector < HTMLButtonElement > (
1714+ '.chat-widget-new-chat'
1715+ ) ;
1716+ if ( newChatButton ) {
1717+ newChatButton . disabled = ! ! this . abortController ;
1718+ }
1719+ }
17041720}
0 commit comments