Skip to content
Snippets Groups Projects
Unverified Commit 69703a54 authored by Avanish Singh's avatar Avanish Singh Committed by GitHub
Browse files

Add files via upload

parent 5398b5c8
No related branches found
No related tags found
No related merge requests found
import React, {useEffect, useRef} from 'react';
import LeftMessage from "./LeftMessage";
import RightMessage from "./RightMessage";
import '../styles/style.css';
const MessageArea = (props) => {
const End = useRef(null)
useEffect(() => {
if(props.messages.length > 0) {
scrollToBottom();
}
})
function scrollToBottom() {
End.current.scrollIntoView({behavior: "smooth"})
}
return (
<div className={props.area}>
{props.messages.map(mes => {
switch (mes.type) {
case "right":
return <RightMessage right_message={mes}/>;
case "left":
return <LeftMessage left_message={mes}/>;
}
})}
<div ref={End}></div>
</div>
);
};
export default MessageArea;
\ No newline at end of file
import React, { useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import TextMessage from "./TextMessage";
import '../styles/style.css';
const MessageSection = (props) => {
const { area, messages } = props;
const End = useRef(null);
useEffect(() => {
if (messages.length > 0) {
scrollToBottom();
}
}, [messages]);
function scrollToBottom() {
End.current.scrollIntoView({ behavior: "smooth" });
}
return (
<div className={area}>
{messages.map((mes) => (
<TextMessage key={mes.id} message={mes} side={mes.type} />
))}
<div ref={End}></div>
</div>
);
};
MessageSection.propTypes = {
area: PropTypes.string.isRequired,
messages: PropTypes.arrayOf(
PropTypes.shape({
id: PropTypes.number.isRequired,
type: PropTypes.oneOf(['left', 'right']).isRequired,
// Add other message properties here
})
).isRequired,
};
export default MessageSection;
import React from 'react';
import '../styles/style.css';
import Message from "./Message";
const TextMessage = (props) => {
const { message, side } = props;
const messageClass = side === 'right' ? 'right_message' : 'left_message';
return (
<div className={messageClass}>
<div className={`icon ${side}`}></div>
<div className={`msg ${side}`}>
<Message message={message} />
</div>
</div>
);
};
export default TextMessage;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment