mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-30 00:53:14 +00:00
adds conversation slice and acomoddates conversation component with the
data types
This commit is contained in:
@@ -1,15 +1,6 @@
|
||||
import { createSlice } from '@reduxjs/toolkit';
|
||||
|
||||
type MESSAGE_TYPE = 'QUESTION' | 'ANSWER';
|
||||
|
||||
interface SingleConversation {
|
||||
message: string;
|
||||
messageType: MESSAGE_TYPE;
|
||||
}
|
||||
|
||||
interface ConversationState {
|
||||
conversation: SingleConversation[];
|
||||
}
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import store from '../store';
|
||||
import { ConversationState, Message } from './conversationModels';
|
||||
|
||||
const initialState: ConversationState = {
|
||||
conversation: [],
|
||||
@@ -19,11 +10,16 @@ export const conversationSlice = createSlice({
|
||||
name: 'conversation',
|
||||
initialState,
|
||||
reducers: {
|
||||
addMessage(state, action) {
|
||||
addMessage(state, action: PayloadAction<Message>) {
|
||||
state.conversation.push(action.payload);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { addMessage } = conversationSlice.actions;
|
||||
|
||||
type RootState = ReturnType<typeof store.getState>;
|
||||
export const selectConversation = (state: RootState) =>
|
||||
state.conversation.conversation;
|
||||
|
||||
export default conversationSlice.reducer;
|
||||
|
||||
Reference in New Issue
Block a user