import PropTypes from 'prop-types'; import { useCallback, useEffect, useRef } from 'react'; // material-ui import { Card, CardContent, Grid, Stack, Typography } from '@mui/material'; // project imports import UserAvatar from './UserAvatar'; // import ChatMessageAction from './ChatMessageAction'; import IconButton from 'components/@extended/IconButton'; import { ThemeMode } from 'config'; // assets import { EditOutlined } from '@ant-design/icons'; // ==============================|| CHAT MESSAGE HISTORY ||============================== // const ChatHistory = ({ data, theme, user }) => { // scroll to bottom when new message is sent or received const wrapper = useRef(document.createElement('div')); const el = wrapper.current; const scrollToBottom = useCallback(() => { el.scrollIntoView(false); }, [el]); useEffect(() => { scrollToBottom(); }, [data.length, scrollToBottom]); return ( {data.map((history, index) => ( {history.from !== user.name ? ( {/* */} {history.text} {history.time} ) : ( {history.text} {history.time} )} ))} ); }; ChatHistory.propTypes = { data: PropTypes.array, theme: PropTypes.object, user: PropTypes.object }; export default ChatHistory;