@@ -10,7 +10,9 @@ import {
1010 IStackTokens ,
1111 mergeStyleSets ,
1212 IModalStyles ,
13- PrimaryButton
13+ PrimaryButton ,
14+ Spinner ,
15+ SpinnerSize
1416} from '@fluentui/react'
1517import { SquareRegular , ShieldLockRegular , ErrorCircleRegular } from '@fluentui/react-icons'
1618
@@ -46,6 +48,7 @@ import { AuthNotConfigure } from './Components/AuthNotConfigure'
4648import { ChatMessageContainer } from './Components/ChatMessageContainer' ;
4749import { parseErrorMessage , cleanJSON } from '../../helpers/helpers' ;
4850
51+
4952const enum messageStatus {
5053 NotRunning = 'Not Running' ,
5154 Processing = 'Processing' ,
@@ -119,6 +122,11 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
119122 const [ isModalOpen , setIsModalOpen ] = useState ( false )
120123 const [ modalUrl , setModalUrl ] = useState ( '' ) ;
121124 const [ finalMessages , setFinalMessages ] = useState < ChatMessage [ ] > ( [ ] )
125+ if ( ! appStateContext || ! appStateContext . state ) {
126+ console . error ( "AppStateContext is undefined. Ensure AppProvider wraps this component." ) ;
127+ return null ; // Prevents execution if context is missing
128+ }
129+ const { currentChat } = appStateContext ?. state ;
122130
123131 const errorDialogContentProps = {
124132 type : DialogType . close ,
@@ -829,19 +837,23 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
829837 ) : (
830838 < Stack horizontal className = { styles . chatRoot } >
831839 < div className = { styles . chatContainer } >
832- { ! messages || messages . length < 1 ? (
840+ { appStateContext . state . isLoading ? (
841+ < Stack horizontalAlign = "center" verticalAlign = "center" className = { styles . chatLoadingState } style = { { padding : 250 , paddingBottom : 150 } } >
842+ < Spinner label = "Loading your chat..." size = { SpinnerSize . large } />
843+ </ Stack >
844+ ) : currentChat ?. messages && currentChat . messages . length > 0 ? (
845+ < ChatMessageContainer
846+ messages = { currentChat . messages }
847+ isLoading = { isLoading }
848+ type = { type }
849+ onShowCitation = { onShowCitation }
850+ showLoadingMessage = { showLoadingMessage }
851+ ref = { chatMessageStreamEnd }
852+ />
853+ ) : (
833854 < Stack className = { styles . chatEmptyState } >
834855 < h1 className = { styles . chatEmptyStateTitle } > { ui ?. chat_title } </ h1 >
835856 </ Stack >
836- ) : (
837- < ChatMessageContainer
838- messages = { messages }
839- isLoading = { isLoading }
840- type = { type }
841- onShowCitation = { onShowCitation }
842- showLoadingMessage = { showLoadingMessage }
843- ref = { chatMessageStreamEnd }
844- />
845857 ) }
846858
847859 < Stack horizontal className = { styles . chatInput } >
0 commit comments