Skip to content

Commit 12ae142

Browse files
Merge pull request #31 from microsoft/adesousa_microsoft/manage-multiple-chat-histories
manage generate and browse histories on the client side
2 parents 261edc3 + e7bddca commit 12ae142

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-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: 6 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
@@ -49,13 +51,17 @@ export type Action =
4951
| { type: 'GET_FEEDBACK_STATE'; payload: string }
5052
| { type: 'UPDATE_SECTION'; payload: { sectionIdx: number; section: Section } }
5153
| { type: 'UPDATE_DRAFTED_DOCUMENT'; payload: DraftedDocument }
54+
| { type: 'UPDATE_BROWSE_CHAT'; payload: Conversation | null }
55+
| { type: 'UPDATE_GENERATE_CHAT'; payload: Conversation | null }
5256

5357
const initialState: AppState = {
5458
isChatHistoryOpen: false,
5559
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
5660
chatHistory: null,
5761
filteredChatHistory: null,
5862
currentChat: null,
63+
browseChat: null,
64+
generateChat: null,
5965
isCosmosDBAvailable: {
6066
cosmosDB: false,
6167
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)