- {/*
- {new Array(10).fill(1).map((item, index) => {
+
+ {messages.map((message, index) => {
return (
);
})}
+ {messages.length === 0 && }
-
*/}
+
);
}
diff --git a/frontend/src/conversation/ConversationBubble.tsx b/frontend/src/conversation/ConversationBubble.tsx
index e5a34f80..6fa99131 100644
--- a/frontend/src/conversation/ConversationBubble.tsx
+++ b/frontend/src/conversation/ConversationBubble.tsx
@@ -1,25 +1,26 @@
+import { forwardRef } from 'react';
import Avatar from '../Avatar';
-import { User } from '../models/misc';
+import { MESSAGE_TYPE } from './conversationModels';
-export default function ConversationBubble({
- user,
- message,
- isCurrentUser,
- className,
-}: {
- user: User;
- message: string;
- isCurrentUser: boolean;
- className: string;
-}) {
+const ConversationBubble = forwardRef<
+ HTMLDivElement,
+ {
+ message: string;
+ type: MESSAGE_TYPE;
+ className: string;
+ }
+>(function ConversationBubble({ message, type, className }, ref) {
return (
);
-}
+});
+
+export default ConversationBubble;
diff --git a/frontend/src/conversation/conversationModels.ts b/frontend/src/conversation/conversationModels.ts
new file mode 100644
index 00000000..1172f769
--- /dev/null
+++ b/frontend/src/conversation/conversationModels.ts
@@ -0,0 +1,10 @@
+export type MESSAGE_TYPE = 'QUESTION' | 'ANSWER';
+
+export interface Message {
+ text: string;
+ type: MESSAGE_TYPE;
+}
+
+export interface ConversationState {
+ conversation: Message[];
+}
diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts
new file mode 100644
index 00000000..a20b3788
--- /dev/null
+++ b/frontend/src/conversation/conversationSlice.ts
@@ -0,0 +1,50 @@
+import { createSlice, PayloadAction } from '@reduxjs/toolkit';
+import store from '../store';
+import { ConversationState, Message } from './conversationModels';
+
+// harcoding the initial state just for demo
+const initialState: ConversationState = {
+ conversation: [
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ { text: 'ChatGPT is large learning model', type: 'ANSWER' },
+ { text: 'what is ChatGPT', type: 'QUESTION' },
+ {
+ text: 'ChatGPT is large learning model',
+ type: 'ANSWER',
+ },
+ ],
+};
+
+export const conversationSlice = createSlice({
+ name: 'conversation',
+ initialState,
+ reducers: {
+ addMessage(state, action: PayloadAction
) {
+ state.conversation.push(action.payload);
+ },
+ },
+});
+
+export const { addMessage } = conversationSlice.actions;
+
+type RootState = ReturnType;
+export const selectConversation = (state: RootState) =>
+ state.conversation.conversation;
+
+export default conversationSlice.reducer;
diff --git a/frontend/src/store.ts b/frontend/src/store.ts
index 706e2ee4..74f573d7 100644
--- a/frontend/src/store.ts
+++ b/frontend/src/store.ts
@@ -1,11 +1,11 @@
-// import { configureStore, createSlice } from '@reduxjs/toolkit';
-
import { configureStore } from '@reduxjs/toolkit';
+import { conversationSlice } from './conversation/conversationSlice';
import { prefSlice } from './preferences/preferenceSlice';
const store = configureStore({
reducer: {
preference: prefSlice.reducer,
+ conversation: conversationSlice.reducer,
},
});