File size: 1,071 Bytes
819bacd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Box, useTheme } from "@mui/material";
import Grid from "@mui/material/Unstable_Grid2";
import { useEffect, useRef } from "react";
import MessageBubble from "../messageBubble";

export default function ChatInterface({ messages }) {
  const theme = useTheme();
  const scrollRef = useRef(null);

  useEffect(() => {
    if (scrollRef.current) {
      scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
    }
  }, [messages]);

  return (
    <>
      <Box
        mb={2}
        display="flex"
        flexDirection="column"
        flexGrow={1}
        padding={2}
        style={{
          border: "2px solid black",
          overflow: "hidden",
          overflowY: "scroll",
          borderRadius: "8px",
          border: "1px solid #ccc",
          backgroundColor: theme.palette.background.default,
        }}
      >
        {messages.map((message, index) => (
          <MessageBubble
            key={index}
            text={message.text}
            isSender={message.isSender}
          />
        ))}
      </Box>
      
    </>
  );
}