Skip to content

Commit b0d46f1

Browse files
Merge pull request microsoft#13 from Roopan-Microsoft/Bug10177
'fix' Edit and Delete btn disable when message is generating, After generating the response in Generate section restricting user to move to another sections.
2 parents d9cc353 + 860bfca commit b0d46f1

File tree

5 files changed

+43
-17
lines changed

5 files changed

+43
-17
lines changed

frontend/src/components/ChatHistory/ChatHistoryListItem.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ export const ChatHistoryListItemCell: React.FC<ChatHistoryListItemCellProps> = (
6060
const [errorRename, setErrorRename] = useState<string | undefined>(undefined)
6161
const [textFieldFocused, setTextFieldFocused] = useState(false)
6262
const textFieldRef = useRef<ITextField | null>(null)
63-
63+
const [isButtonDisabled, setIsButtonDisabled] = useState<boolean>(false);
64+
6465
const appStateContext = React.useContext(AppStateContext)
6566
const isSelected = item?.id === appStateContext?.state.currentChat?.id
6667
const dialogContentProps = {
@@ -95,6 +96,12 @@ export const ChatHistoryListItemCell: React.FC<ChatHistoryListItemCellProps> = (
9596
}
9697
}, [appStateContext?.state.currentChat?.id, item?.id])
9798

99+
useEffect(()=>{
100+
let v = appStateContext?.state.isRequestInitiated;
101+
if(v!=undefined)
102+
setIsButtonDisabled(v && isSelected)
103+
},[appStateContext?.state.isRequestInitiated])
104+
98105
const onDelete = async () => {
99106
const response = await historyDelete(item.id)
100107
if (!response.ok) {
@@ -267,13 +274,15 @@ export const ChatHistoryListItemCell: React.FC<ChatHistoryListItemCellProps> = (
267274
iconProps={{ iconName: 'Delete' }}
268275
title="Delete"
269276
onClick={toggleDeleteDialog}
277+
disabled={isButtonDisabled}
270278
onKeyDown={e => (e.key === ' ' ? toggleDeleteDialog() : null)}
271279
/>
272280
<IconButton
273281
className={styles.itemButton}
274282
iconProps={{ iconName: 'Edit' }}
275283
title="Edit"
276284
onClick={onEdit}
285+
disabled={isButtonDisabled}
277286
onKeyDown={e => (e.key === ' ' ? onEdit() : null)}
278287
/>
279288
</Stack>

frontend/src/components/Sidebar/Sidebar.tsx

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ const Sidebar = (): JSX.Element => {
8585
const navigate = useNavigate()
8686
const location = useLocation()
8787
const [name, setName] = useState<string>('')
88+
useEffect(() => {
89+
if(appStateContext?.state.isRequestInitiated == true){
90+
NavigationButtonStates.Disabled
91+
}
92+
else{
93+
NavigationButtonStates.Active
94+
}
95+
})
8896

8997
useEffect(() => {
9098
if (!appStateContext) {
@@ -113,7 +121,12 @@ const Sidebar = (): JSX.Element => {
113121
}
114122

115123
const currentView = determineView()
116-
const isGenerating = appStateContext?.state.isGenerating
124+
// inactive, disabled, active
125+
var draftButtonState = NavigationButtonStates.Disabled
126+
if (appStateContext?.state.draftedDocument) {
127+
draftButtonState = currentView === 'draft' ? NavigationButtonStates.Active : NavigationButtonStates.Inactive
128+
}
129+
const isGenerating = appStateContext?.state.isRequestInitiated
117130

118131
return (
119132
<Stack className={styles.sidebarContainer}>
@@ -125,9 +138,9 @@ const Sidebar = (): JSX.Element => {
125138
text={'Browse'}
126139
buttonState={
127140
currentView === 'chat'
128-
? NavigationButtonStates.Active
129-
: appStateContext?.state.isGenerating
130-
? NavigationButtonStates.Disabled
141+
? NavigationButtonStates.Active
142+
: appStateContext?.state.isRequestInitiated
143+
? NavigationButtonStates.Disabled
131144
: NavigationButtonStates.Inactive
132145
}
133146
onClick={() => {
@@ -141,9 +154,10 @@ const Sidebar = (): JSX.Element => {
141154
buttonState={
142155
currentView === 'generate'
143156
? NavigationButtonStates.Active
144-
: appStateContext?.state.isGenerating
157+
: appStateContext?.state.isRequestInitiated
145158
? NavigationButtonStates.Disabled
146159
: NavigationButtonStates.Inactive
160+
147161
}
148162
onClick={() => {
149163
if (!isGenerating) {
@@ -153,17 +167,10 @@ const Sidebar = (): JSX.Element => {
153167
/>
154168
<NavigationButton
155169
text={'Draft'}
156-
buttonState={
157-
currentView === 'draft'
158-
? NavigationButtonStates.Active
159-
: appStateContext?.state.isGenerating
160-
? NavigationButtonStates.Disabled
161-
: NavigationButtonStates.Inactive
162-
}
170+
buttonState={draftButtonState}
171+
163172
onClick={() => {
164-
if (!isGenerating) {
165-
navigate('/draft')
166-
}
173+
navigate('/draft')
167174
}}
168175
/>
169176
</Stack>

frontend/src/pages/chat/Chat.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
287287
setShowLoadingMessage(true)
288288
const abortController = new AbortController()
289289
abortFuncs.current.unshift(abortController)
290+
appStateContext?.dispatch({ type: 'SET_IS_REQUEST_INITIATED', payload: true })
290291

291292
const userMessage: ChatMessage = {
292293
id: uuid(),
@@ -402,6 +403,7 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
402403
setShowLoadingMessage(false)
403404
appStateContext?.dispatch({ type: 'GENERATE_ISLODING', payload: false })
404405
abortFuncs.current = abortFuncs.current.filter(a => a !== abortController)
406+
appStateContext?.dispatch({ type: 'SET_IS_REQUEST_INITIATED', payload: false })
405407
setProcessMessages(messageStatus.Done)
406408
}
407409

@@ -414,6 +416,8 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
414416
setShowLoadingMessage(true)
415417
const abortController = new AbortController()
416418
abortFuncs.current.unshift(abortController)
419+
appStateContext?.dispatch({ type: 'SET_IS_REQUEST_INITIATED', payload: true })
420+
417421

418422
const userMessage: ChatMessage = {
419423
id: uuid(),
@@ -640,6 +644,7 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
640644
setShowLoadingMessage(false)
641645
abortFuncs.current = abortFuncs.current.filter(a => a !== abortController)
642646
setProcessMessages(messageStatus.Done)
647+
appStateContext?.dispatch({ type: 'SET_IS_REQUEST_INITIATED', payload: false })
643648
}
644649
return abortController.abort()
645650
}

frontend/src/state/AppProvider.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export interface AppState {
3030
draftedDocument: DraftedDocument | null
3131
draftedDocumentTitle: string
3232
isGenerating: boolean
33+
isRequestInitiated : boolean
3334
}
3435

3536
export type Action =
@@ -56,6 +57,7 @@ export type Action =
5657
| { type: 'UPDATE_GENERATE_CHAT'; payload: Conversation | null }
5758
| { type: 'UPDATE_DRAFTED_DOCUMENT_TITLE'; payload: string }
5859
| { type: 'GENERATE_ISLODING'; payload: boolean }
60+
| { type: 'SET_IS_REQUEST_INITIATED'; payload: boolean }
5961

6062
const initialState: AppState = {
6163
isChatHistoryOpen: false,
@@ -73,7 +75,8 @@ const initialState: AppState = {
7375
feedbackState: {},
7476
draftedDocument: null,
7577
draftedDocumentTitle: '',
76-
isGenerating: false
78+
isGenerating: false,
79+
isRequestInitiated: false,
7780
}
7881

7982
export const AppStateContext = createContext<

frontend/src/state/AppReducer.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ export const appStateReducer = (state: AppState, action: Action): AppState => {
103103
return { ...state, draftedDocumentTitle: action.payload }
104104
case 'GENERATE_ISLODING':
105105
return { ...state, isGenerating: action.payload }
106+
case 'SET_IS_REQUEST_INITIATED' :
107+
return {...state, isRequestInitiated : action.payload}
106108
default:
107109
return state
108110
}

0 commit comments

Comments
 (0)