diff --git a/frontend/src/conversation/Conversation.tsx b/frontend/src/conversation/Conversation.tsx index 71d2f52..2d54699 100644 --- a/frontend/src/conversation/Conversation.tsx +++ b/frontend/src/conversation/Conversation.tsx @@ -1,3 +1,4 @@ +import { useEffect, useRef } from 'react'; import { useSelector } from 'react-redux'; import Hero from '../Hero'; import ConversationBubble from './ConversationBubble'; @@ -6,13 +7,18 @@ import { selectConversation } from './conversationSlice'; export default function Conversation() { const messages = useSelector(selectConversation); + const endMessageRef = useRef(null); + + useEffect(() => endMessageRef?.current?.scrollIntoView()); + return (
{messages.map((message, index) => { return ( (function ConversationBubble({ message, type, className }, ref) { return (
{message}

); -} +}); + +export default ConversationBubble; diff --git a/frontend/src/conversation/conversationSlice.ts b/frontend/src/conversation/conversationSlice.ts index eaec819..a20b378 100644 --- a/frontend/src/conversation/conversationSlice.ts +++ b/frontend/src/conversation/conversationSlice.ts @@ -2,8 +2,33 @@ 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: [], + 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({