2020-10-12 06:25:59 -04:00
|
|
|
import PropTypes from 'prop-types'
|
2021-05-18 09:43:36 -04:00
|
|
|
import { getHueForUserId } from '../../../shared/utils/colors'
|
2020-10-12 06:25:59 -04:00
|
|
|
import MessageContent from './message-content'
|
|
|
|
|
|
|
|
function Message({ message, userId }) {
|
|
|
|
function hue(user) {
|
2021-05-18 09:43:36 -04:00
|
|
|
return user ? getHueForUserId(user.id, userId) : 0
|
2020-10-12 06:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function getMessageStyle(user) {
|
|
|
|
return {
|
2021-02-22 11:21:43 -05:00
|
|
|
borderColor: `hsl(${hue(user)}, 85%, 40%)`,
|
2021-04-27 03:52:58 -04:00
|
|
|
backgroundColor: `hsl(${hue(user)}, 85%, 40%`,
|
2020-10-12 06:25:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getArrowStyle(user) {
|
|
|
|
return {
|
2021-04-27 03:52:58 -04:00
|
|
|
borderColor: `hsl(${hue(user)}, 85%, 40%)`,
|
2020-10-12 06:25:59 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const isMessageFromSelf = message.user ? message.user.id === userId : false
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="message-wrapper">
|
|
|
|
{!isMessageFromSelf && (
|
|
|
|
<div className="name">
|
|
|
|
<span>{message.user.first_name || message.user.email}</span>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
<div className="message" style={getMessageStyle(message.user)}>
|
|
|
|
{!isMessageFromSelf && (
|
|
|
|
<div className="arrow" style={getArrowStyle(message.user)} />
|
|
|
|
)}
|
|
|
|
<div className="message-content">
|
|
|
|
{message.contents.map((content, index) => (
|
|
|
|
<MessageContent key={index} content={content} />
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
Message.propTypes = {
|
|
|
|
message: PropTypes.shape({
|
|
|
|
contents: PropTypes.arrayOf(PropTypes.string).isRequired,
|
|
|
|
user: PropTypes.shape({
|
|
|
|
id: PropTypes.string,
|
|
|
|
email: PropTypes.string,
|
2021-04-27 03:52:58 -04:00
|
|
|
first_name: PropTypes.string,
|
|
|
|
}),
|
2020-10-12 06:25:59 -04:00
|
|
|
}),
|
2024-08-29 10:39:47 -04:00
|
|
|
userId: PropTypes.string,
|
2020-10-12 06:25:59 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
export default Message
|