Skip to content

Commit e5e0348

Browse files
author
adesousa_microsoft
committed
manage generate and browse histories on the client side
1 parent 261edc3 commit e5e0348

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

frontend/src/pages/chat/Chat.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
101101

102102
useEffect(() => {
103103
console.log('Route changed, refresh the contents');
104-
refreshContent();
104+
105+
if (type === ChatType.Browse) {
106+
appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: appStateContext?.state.browseChat });
107+
} else {
108+
appStateContext?.dispatch({ type: 'UPDATE_CURRENT_CHAT', payload: appStateContext?.state.generateChat });
109+
}
105110
}, [location]);
106111

112+
107113
useEffect(() => {
108114
if (
109115
appStateContext?.state.isCosmosDBAvailable?.status !== CosmosDBStatus.Working &&
@@ -697,6 +703,13 @@ const Chat = ({ type = ChatType.Browse }: Props) => {
697703
} else {
698704
setMessages([])
699705
}
706+
707+
if (type === ChatType.Browse) {
708+
appStateContext?.dispatch({ type: 'UPDATE_BROWSE_CHAT', payload: appStateContext?.state.currentChat });
709+
} else {
710+
appStateContext?.dispatch({ type: 'UPDATE_GENERATE_CHAT', payload: appStateContext?.state.currentChat })
711+
}
712+
700713
}, [appStateContext?.state.currentChat])
701714

702715
useLayoutEffect(() => {

frontend/src/state/AppProvider.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export interface AppState {
2424
chatHistory: Conversation[] | null
2525
filteredChatHistory: Conversation[] | null
2626
currentChat: Conversation | null
27+
browseChat: Conversation | null
28+
generateChat: Conversation | null
2729
frontendSettings: FrontendSettings | null
2830
feedbackState: { [answerId: string]: Feedback.Neutral | Feedback.Positive | Feedback.Negative }
2931
draftedDocument: DraftedDocument | null
@@ -56,6 +58,8 @@ const initialState: AppState = {
5658
chatHistory: null,
5759
filteredChatHistory: null,
5860
currentChat: null,
61+
browseChat: null,
62+
generateChat: null,
5963
isCosmosDBAvailable: {
6064
cosmosDB: false,
6165
status: CosmosDBStatus.NotConfigured

frontend/src/state/AppReducer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ export const appStateReducer = (state: AppState, action: Action): AppState => {
9595
}
9696
case 'UPDATE_DRAFTED_DOCUMENT':
9797
return { ...state, draftedDocument: action.payload }
98+
case 'UPDATE_BROWSE_CHAT':
99+
return { ...state, browseChat: action.payload }
100+
case 'UPDATE_GENERATE_CHAT':
101+
return { ...state, generateChat: action.payload }
98102
default:
99103
return state
100104
}

0 commit comments

Comments
 (0)