adds conversation slice and acomoddates conversation component with the

data types
This commit is contained in:
ajaythapliyal
2023-02-19 10:36:26 +05:30
parent d20b5f3e09
commit 5b456cda16
4 changed files with 34 additions and 30 deletions

View File

@@ -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;