Skip to content

Commit 83f7b62

Browse files
Merge pull request #296 from microsoft/psl-15563-chatPanel
fix: implementation of chat page
2 parents 9f3452a + 618455b commit 83f7b62

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

frontend/src/components/ChatHistory/ChatHistoryPanel.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,17 +199,18 @@ export function ChatHistoryPanel(_props: ChatHistoryPanelProps) {
199199
horizontal
200200
horizontalAlign="center"
201201
verticalAlign="center"
202-
style={{ width: '100%', marginTop: 10 }}>
203-
<StackItem style={{ justifyContent: 'center', alignItems: 'center' }}>
204-
<Spinner
205-
style={{ alignSelf: 'flex-start', height: '100%', marginRight: '5px' }}
206-
size={SpinnerSize.medium}
207-
/>
208-
</StackItem>
202+
style={{ width: '100%', height: '80vh' }} // Ensure it takes full height
203+
>
209204
<StackItem>
210-
<Text style={{ alignSelf: 'center', fontWeight: '400', fontSize: 14 }}>
211-
<span style={{ whiteSpace: 'pre-wrap' }}>Loading chat history</span>
212-
</Text>
205+
<Stack horizontal verticalAlign="center">
206+
<Spinner
207+
style={{ marginRight: '5px' }}
208+
size={SpinnerSize.medium}
209+
/>
210+
<Text style={{ fontWeight: '400', fontSize: 14 }}>
211+
<span style={{ whiteSpace: 'pre-wrap' }}>Loading chat history</span>
212+
</Text>
213+
</Stack>
213214
</StackItem>
214215
</Stack>
215216
</Stack>

frontend/src/pages/chat/Chat.tsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
126126
console.error("AppStateContext is undefined. Ensure AppProvider wraps this component.");
127127
return null; // Prevents execution if context is missing
128128
}
129+
const [loadingState, setLoadingState] = useState(appStateContext.state.isLoading);
129130
const { currentChat } = appStateContext?.state;
130131

131132
const errorDialogContentProps = {
@@ -158,6 +159,10 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
158159
appStateContext?.dispatch({ type: 'GENERATE_ISLODING', payload: appStateContext?.state.isGenerating })
159160
}, [isLoading])
160161

162+
useEffect(() => {
163+
setLoadingState(appStateContext.state.isLoading)
164+
}, [appStateContext.state.isLoading])
165+
161166
useEffect(() => {
162167
if (
163168
appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working &&
@@ -837,23 +842,24 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
837842
) : (
838843
<Stack horizontal className={styles.chatRoot}>
839844
<div className={styles.chatContainer}>
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+
{ loadingState ? (
846+
<Stack horizontalAlign="center" verticalAlign="center" className={styles.chatLoadingState} style={{padding: 250, paddingBottom: 150}}>
847+
<Spinner label="Loading your chat..." size={SpinnerSize.large} />
848+
</Stack>
849+
) : !messages || messages.length < 1 ? (
850+
<Stack className={styles.chatEmptyState}>
851+
<h1 className={styles.chatEmptyStateTitle}>{ui?.chat_title}</h1>
852+
</Stack>
853+
) : (
854+
// Show chat messages while loading continues in the background
845855
<ChatMessageContainer
846-
messages={currentChat.messages}
847-
isLoading={isLoading}
856+
messages={messages}
857+
isLoading={isLoading} // Keep isLoading for progressive updates
848858
type={type}
849859
onShowCitation={onShowCitation}
850860
showLoadingMessage={showLoadingMessage}
851861
ref={chatMessageStreamEnd}
852862
/>
853-
) : (
854-
<Stack className={styles.chatEmptyState}>
855-
<h1 className={styles.chatEmptyStateTitle}>{ui?.chat_title}</h1>
856-
</Stack>
857863
)}
858864

859865
<Stack horizontal className={styles.chatInput}>

0 commit comments

Comments
 (0)