Skip to content

Commit

Permalink
[fix] Flashing Contoso logo when custom logo is present
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Seabock (Centific Technologies Inc) committed Jul 10, 2024
1 parent f7aaab3 commit c4dc14f
Show file tree
Hide file tree
Showing 9 changed files with 3,796 additions and 119 deletions.
9 changes: 8 additions & 1 deletion frontend/src/pages/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const Chat = () => {
const [clearingChat, setClearingChat] = useState<boolean>(false)
const [hideErrorDialog, { toggle: toggleErrorDialog }] = useBoolean(true)
const [errorMsg, setErrorMsg] = useState<ErrorMessage | null>()
const [logo, setLogo] = useState('')

const errorDialogContentProps = {
type: DialogType.close,
Expand Down Expand Up @@ -104,6 +105,12 @@ const Chat = () => {
}, 500)
}

useEffect(() => {
if (!appStateContext?.state.isLoading) {
setLogo(ui?.logo || Contoso)
}
}, [appStateContext?.state.isLoading])

useEffect(() => {
setIsLoading(appStateContext?.state.chatHistoryLoadingState === ChatHistoryLoadingState.Loading)
}, [appStateContext?.state.chatHistoryLoadingState])
Expand Down Expand Up @@ -766,7 +773,7 @@ const Chat = () => {
<div className={styles.chatContainer}>
{!messages || messages.length < 1 ? (
<Stack className={styles.chatEmptyState}>
<img src={ui?.chat_logo ? ui.chat_logo : Contoso} className={styles.chatIcon} aria-hidden="true" />
<img src={logo} className={styles.chatIcon} aria-hidden="true" />
<h1 className={styles.chatEmptyStateTitle}>{ui?.chat_title}</h1>
<h2 className={styles.chatEmptyStateSubtitle}>{ui?.chat_description}</h2>
</Stack>
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/pages/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const Layout = () => {
const [shareLabel, setShareLabel] = useState<string | undefined>('Share')
const [hideHistoryLabel, setHideHistoryLabel] = useState<string>('Hide chat history')
const [showHistoryLabel, setShowHistoryLabel] = useState<string>('Show chat history')
const [logo, setLogo] = useState('')
const appStateContext = useContext(AppStateContext)
const ui = appStateContext?.state.frontendSettings?.ui

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

useEffect(() => {
if (!appStateContext?.state.isLoading) {
setLogo(ui?.logo || Contoso)
}
}, [appStateContext?.state.isLoading])

useEffect(() => {
if (copyClicked) {
setCopyText('Copied URL')
Expand Down Expand Up @@ -71,7 +78,7 @@ const Layout = () => {
<header className={styles.header} role={'banner'}>
<Stack horizontal verticalAlign="center" horizontalAlign="space-between">
<Stack horizontal verticalAlign="center">
<img src={ui?.logo ? ui.logo : Contoso} className={styles.headerIcon} aria-hidden="true" alt="" />
<img src={logo} className={styles.headerIcon} aria-hidden="true" alt="" />
<Link to="/" className={styles.headerTitleContainer}>
<h1 className={styles.headerTitle}>{ui?.title}</h1>
</Link>
Expand Down
24 changes: 15 additions & 9 deletions frontend/src/state/AppProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React, { createContext, ReactNode, useEffect,
useReducer } from 'react'
import React, {
createContext,
ReactNode,
useEffect,
useReducer
} from 'react'

import {
ChatHistoryLoadingState,
Expand All @@ -24,6 +28,7 @@ export interface AppState {
currentChat: Conversation | null
frontendSettings: FrontendSettings | null
feedbackState: { [answerId: string]: Feedback.Neutral | Feedback.Positive | Feedback.Negative }
isLoading: boolean;
}

export type Action =
Expand All @@ -40,9 +45,9 @@ export type Action =
| { type: 'FETCH_CHAT_HISTORY'; payload: Conversation[] | null }
| { type: 'FETCH_FRONTEND_SETTINGS'; payload: FrontendSettings | null }
| {
type: 'SET_FEEDBACK_STATE'
payload: { answerId: string; feedback: Feedback.Positive | Feedback.Negative | Feedback.Neutral }
}
type: 'SET_FEEDBACK_STATE'
payload: { answerId: string; feedback: Feedback.Positive | Feedback.Negative | Feedback.Neutral }
}
| { type: 'GET_FEEDBACK_STATE'; payload: string }

const initialState: AppState = {
Expand All @@ -56,14 +61,15 @@ const initialState: AppState = {
status: CosmosDBStatus.NotConfigured
},
frontendSettings: null,
feedbackState: {}
feedbackState: {},
isLoading: true
}

export const AppStateContext = createContext<
| {
state: AppState
dispatch: React.Dispatch<Action>
}
state: AppState
dispatch: React.Dispatch<Action>
}
| undefined
>(undefined)

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/state/AppReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const appStateReducer = (state: AppState, action: Action): AppState => {
case 'SET_COSMOSDB_STATUS':
return { ...state, isCosmosDBAvailable: action.payload }
case 'FETCH_FRONTEND_SETTINGS':
return { ...state, frontendSettings: action.payload }
return { ...state, isLoading: false, frontendSettings: action.payload }
case 'SET_FEEDBACK_STATE':
return {
...state,
Expand Down
3,643 changes: 3,643 additions & 0 deletions static/assets/index-79e9aacc.js

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions static/assets/index-79e9aacc.js.map

Large diffs are not rendered by default.

215 changes: 110 additions & 105 deletions static/assets/index-eaff1adf.js

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion static/assets/index-eaff1adf.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<link rel="icon" type="image/x-icon" href="{{ favicon }}" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>{{ title }}</title>
<script type="module" crossorigin src="/assets/index-eaff1adf.js"></script>
<script type="module" crossorigin src="/assets/index-79e9aacc.js"></script>
<link rel="stylesheet" href="/assets/index-61492790.css">
</head>
<body>
Expand Down

0 comments on commit c4dc14f

Please sign in to comment.