import * as React from 'react'; import Box from '@mui/joy/Box'; import Sheet from '@mui/joy/Sheet'; import Stack from '@mui/joy/Stack'; import AvatarWithStatus from './AvatarWithStatus'; import ChatBubble from './ChatBubble'; import MessageInput from './MessageInput'; import MessagesPaneHeader from './MessagesPaneHeader'; import { ChatProps, MessageProps } from '../types'; type MessagesPaneProps = { chat: ChatProps; }; export default function MessagesPane(props: MessagesPaneProps) { const { chat } = props; const [chatMessages, setChatMessages] = React.useState(chat.messages); const [textAreaValue, setTextAreaValue] = React.useState(''); React.useEffect(() => { setChatMessages(chat.messages); }, [chat.messages]); return ( {chatMessages.map((message: MessageProps, index: number) => { const isYou = message.sender === 'You'; return ( {message.sender !== 'You' && ( )} ); })} { const newId = chatMessages.length + 1; const newIdString = newId.toString(); setChatMessages([ ...chatMessages, { id: newIdString, sender: 'You', content: textAreaValue, timestamp: 'Just now', }, ]); }} /> ); }