From 1b6e271b331352af825b5ca831cf9249efb95e2f Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Thu, 31 Oct 2024 12:13:49 -0700 Subject: [PATCH] Fix: Load multiple chats during first startup --- webapp/src/App.tsx | 18 +++++++++++------- webapp/src/components/chat/Chat.tsx | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/webapp/src/App.tsx b/webapp/src/App.tsx index 65100c3e7..75ac3abd1 100644 --- a/webapp/src/App.tsx +++ b/webapp/src/App.tsx @@ -2,7 +2,7 @@ import { AuthenticatedTemplate, UnauthenticatedTemplate, useIsAuthenticated, use import { FluentProvider, Subtitle1, makeStyles, shorthands, tokens } from '@fluentui/react-components'; import * as React from 'react'; -import { useEffect, useCallback } from 'react'; +import { useCallback, useEffect } from 'react'; import Chat from './components/chat/Chat'; import { Loading, Login } from './components/views'; import { AuthHelper } from './libs/auth/AuthHelper'; @@ -49,6 +49,7 @@ export enum AppState { SettingUserInfo, ErrorLoadingChats, ErrorLoadingUserInfo, + LoadChats, LoadingChats, Chat, SigningOut, @@ -98,16 +99,20 @@ const App = () => { ); } - handleAppStateChange(AppState.LoadingChats); + handleAppStateChange(AppState.LoadChats); } } - if ((isAuthenticated || !AuthHelper.isAuthAAD()) && appState === AppState.LoadingChats) { + if ((isAuthenticated || !AuthHelper.isAuthAAD()) && appState === AppState.LoadChats) { + handleAppStateChange(AppState.LoadingChats); void Promise.all([ - chat.loadChats() - .then(() => { handleAppStateChange(AppState.Chat); }) + chat + .loadChats() + .then(() => { + handleAppStateChange(AppState.Chat); + }) .catch((error) => { - console.error("Error loading chats:", error); + console.error('Error loading chats:', error); handleAppStateChange(AppState.ErrorLoadingChats); }), file.getContentSafetyStatus(), @@ -118,7 +123,6 @@ const App = () => { }), ]); } - }, [instance, isAuthenticated, appState, isMaintenance, handleAppStateChange, dispatch, chat, file]); const theme = features[FeatureKeys.DarkMode].enabled ? semanticKernelDarkTheme : semanticKernelLightTheme; diff --git a/webapp/src/components/chat/Chat.tsx b/webapp/src/components/chat/Chat.tsx index 134182aa6..ff9801aec 100644 --- a/webapp/src/components/chat/Chat.tsx +++ b/webapp/src/components/chat/Chat.tsx @@ -21,7 +21,7 @@ const Chat = ({ ? // if AAD is enabled, we need to set the active account before loading chats AppState.SettingUserInfo : // otherwise, we can load chats immediately - AppState.LoadingChats, + AppState.LoadChats, ); }, [setAppState]); return (