Skip to content

Commit e256fd1

Browse files
iseabockIan Seabock (Centific Technologies Inc)
andauthored
[fix] Flashing Contoso logo when custom logo is present (#962)
Co-authored-by: Ian Seabock (Centific Technologies Inc) <v-ianseabock@microsoft.com>
1 parent f7aaab3 commit e256fd1

File tree

7 files changed

+141
-121
lines changed

7 files changed

+141
-121
lines changed

frontend/src/pages/chat/Chat.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const Chat = () => {
6363
const [clearingChat, setClearingChat] = useState<boolean>(false)
6464
const [hideErrorDialog, { toggle: toggleErrorDialog }] = useBoolean(true)
6565
const [errorMsg, setErrorMsg] = useState<ErrorMessage | null>()
66+
const [logo, setLogo] = useState('')
6667

6768
const errorDialogContentProps = {
6869
type: DialogType.close,
@@ -104,6 +105,12 @@ const Chat = () => {
104105
}, 500)
105106
}
106107

108+
useEffect(() => {
109+
if (!appStateContext?.state.isLoading) {
110+
setLogo(ui?.chat_logo || ui?.logo || Contoso)
111+
}
112+
}, [appStateContext?.state.isLoading])
113+
107114
useEffect(() => {
108115
setIsLoading(appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading)
109116
}, [appStateContext?.state.chatHistoryLoadingState])
@@ -766,7 +773,7 @@ const Chat = () => {
766773
<div className={styles.chatContainer}>
767774
{!messages || messages.length < 1 ? (
768775
<Stack className={styles.chatEmptyState}>
769-
<img src={ui?.chat_logo ? ui.chat_logo : Contoso} className={styles.chatIcon} aria-hidden="true" />
776+
<img src={logo} className={styles.chatIcon} aria-hidden="true" />
770777
<h1 className={styles.chatEmptyStateTitle}>{ui?.chat_title}</h1>
771778
<h2 className={styles.chatEmptyStateSubtitle}>{ui?.chat_description}</h2>
772779
</Stack>

frontend/src/pages/layout/Layout.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const Layout = () => {
1717
const [shareLabel, setShareLabel] = useState<string | undefined>('Share')
1818
const [hideHistoryLabel, setHideHistoryLabel] = useState<string>('Hide chat history')
1919
const [showHistoryLabel, setShowHistoryLabel] = useState<string>('Show chat history')
20+
const [logo, setLogo] = useState('')
2021
const appStateContext = useContext(AppStateContext)
2122
const ui = appStateContext?.state.frontendSettings?.ui
2223

@@ -39,6 +40,12 @@ const Layout = () => {
3940
appStateContext?.dispatch({ type: 'TOGGLE_CHAT_HISTORY' })
4041
}
4142

43+
useEffect(() => {
44+
if (!appStateContext?.state.isLoading) {
45+
setLogo(ui?.logo || Contoso)
46+
}
47+
}, [appStateContext?.state.isLoading])
48+
4249
useEffect(() => {
4350
if (copyClicked) {
4451
setCopyText('Copied URL')
@@ -71,7 +78,7 @@ const Layout = () => {
7178
<header className={styles.header} role={'banner'}>
7279
<Stack horizontal verticalAlign="center" horizontalAlign="space-between">
7380
<Stack horizontal verticalAlign="center">
74-
<img src={ui?.logo ? ui.logo : Contoso} className={styles.headerIcon} aria-hidden="true" alt="" />
81+
<img src={logo} className={styles.headerIcon} aria-hidden="true" alt="" />
7582
<Link to="/" className={styles.headerTitleContainer}>
7683
<h1 className={styles.headerTitle}>{ui?.title}</h1>
7784
</Link>

frontend/src/state/AppProvider.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
import React, { createContext, ReactNode, useEffect,
2-
useReducer } from 'react'
1+
import React, {
2+
createContext,
3+
ReactNode,
4+
useEffect,
5+
useReducer
6+
} from 'react'
37

48
import {
59
ChatHistoryLoadingState,
@@ -24,6 +28,7 @@ export interface AppState {
2428
currentChat: Conversation | null
2529
frontendSettings: FrontendSettings | null
2630
feedbackState: { [answerId: string]: Feedback.Neutral | Feedback.Positive | Feedback.Negative }
31+
isLoading: boolean;
2732
}
2833

2934
export type Action =
@@ -40,9 +45,9 @@ export type Action =
4045
| { type: 'FETCH_CHAT_HISTORY'; payload: Conversation[] | null }
4146
| { type: 'FETCH_FRONTEND_SETTINGS'; payload: FrontendSettings | null }
4247
| {
43-
type: 'SET_FEEDBACK_STATE'
44-
payload: { answerId: string; feedback: Feedback.Positive | Feedback.Negative | Feedback.Neutral }
45-
}
48+
type: 'SET_FEEDBACK_STATE'
49+
payload: { answerId: string; feedback: Feedback.Positive | Feedback.Negative | Feedback.Neutral }
50+
}
4651
| { type: 'GET_FEEDBACK_STATE'; payload: string }
4752

4853
const initialState: AppState = {
@@ -56,14 +61,15 @@ const initialState: AppState = {
5661
status: CosmosDBStatus.NotConfigured
5762
},
5863
frontendSettings: null,
59-
feedbackState: {}
64+
feedbackState: {},
65+
isLoading: true
6066
}
6167

6268
export const AppStateContext = createContext<
6369
| {
64-
state: AppState
65-
dispatch: React.Dispatch<Action>
66-
}
70+
state: AppState
71+
dispatch: React.Dispatch<Action>
72+
}
6773
| undefined
6874
>(undefined)
6975

frontend/src/state/AppReducer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const appStateReducer = (state: AppState, action: Action): AppState => {
6565
case 'SET_COSMOSDB_STATUS':
6666
return { ...state, isCosmosDBAvailable: action.payload }
6767
case 'FETCH_FRONTEND_SETTINGS':
68-
return { ...state, frontendSettings: action.payload }
68+
return { ...state, isLoading: false, frontendSettings: action.payload }
6969
case 'SET_FEEDBACK_STATE':
7070
return {
7171
...state,

0 commit comments

Comments
 (0)