Skip to content

Commit 7b27658

Browse files
authored
Fix: Load multiple chats during first startup (#1198)
### Motivation and Context <!-- Thank you for your contribution to the chat-copilot repo! Please help reviewers and future users, providing the following information: 1. Why is this change required? 2. What problem does it solve? 3. What scenario does it contribute to? 4. If it fixes an open issue, please link to the issue here. --> When the application initially starts without any chat sessions in the database, the app will attempt to create a new one. Currently, the app will attempt multiple times without waiting for the initial attempt to finish. This PR fixes the issue by introducing an intermediate state. ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [Contribution Guidelines](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/chat-copilot/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent ee8df9c commit 7b27658

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

webapp/src/App.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AuthenticatedTemplate, UnauthenticatedTemplate, useIsAuthenticated, use
22
import { FluentProvider, Subtitle1, makeStyles, shorthands, tokens } from '@fluentui/react-components';
33

44
import * as React from 'react';
5-
import { useEffect, useCallback } from 'react';
5+
import { useCallback, useEffect } from 'react';
66
import Chat from './components/chat/Chat';
77
import { Loading, Login } from './components/views';
88
import { AuthHelper } from './libs/auth/AuthHelper';
@@ -49,6 +49,7 @@ export enum AppState {
4949
SettingUserInfo,
5050
ErrorLoadingChats,
5151
ErrorLoadingUserInfo,
52+
LoadChats,
5253
LoadingChats,
5354
Chat,
5455
SigningOut,
@@ -98,16 +99,20 @@ const App = () => {
9899
);
99100
}
100101

101-
handleAppStateChange(AppState.LoadingChats);
102+
handleAppStateChange(AppState.LoadChats);
102103
}
103104
}
104105

105-
if ((isAuthenticated || !AuthHelper.isAuthAAD()) && appState === AppState.LoadingChats) {
106+
if ((isAuthenticated || !AuthHelper.isAuthAAD()) && appState === AppState.LoadChats) {
107+
handleAppStateChange(AppState.LoadingChats);
106108
void Promise.all([
107-
chat.loadChats()
108-
.then(() => { handleAppStateChange(AppState.Chat); })
109+
chat
110+
.loadChats()
111+
.then(() => {
112+
handleAppStateChange(AppState.Chat);
113+
})
109114
.catch((error) => {
110-
console.error("Error loading chats:", error);
115+
console.error('Error loading chats:', error);
111116
handleAppStateChange(AppState.ErrorLoadingChats);
112117
}),
113118
file.getContentSafetyStatus(),
@@ -118,7 +123,6 @@ const App = () => {
118123
}),
119124
]);
120125
}
121-
122126
}, [instance, isAuthenticated, appState, isMaintenance, handleAppStateChange, dispatch, chat, file]);
123127

124128
const theme = features[FeatureKeys.DarkMode].enabled ? semanticKernelDarkTheme : semanticKernelLightTheme;

webapp/src/components/chat/Chat.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const Chat = ({
2121
? // if AAD is enabled, we need to set the active account before loading chats
2222
AppState.SettingUserInfo
2323
: // otherwise, we can load chats immediately
24-
AppState.LoadingChats,
24+
AppState.LoadChats,
2525
);
2626
}, [setAppState]);
2727
return (

0 commit comments

Comments
 (0)