Skip to content

Commit 3db1fc8

Browse files
author
Himanshi Agrawal
committed
Bug10177 fixed Edit and Delete btn disable when message is generating
1 parent 77eee2b commit 3db1fc8

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
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/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)