2022-08-23 21:46:07 -05:00
|
|
|
import Typography from '@mui/material/Typography'
|
|
|
|
|
|
|
|
import { Message as IMessage, isMessageReceived } from 'models/chat'
|
|
|
|
|
|
|
|
export interface MessageProps {
|
|
|
|
message: IMessage
|
|
|
|
userId: string
|
|
|
|
}
|
|
|
|
|
|
|
|
export const Message = ({ message, userId }: MessageProps) => {
|
|
|
|
let backgroundColor: string
|
|
|
|
|
|
|
|
if (message.authorId === userId) {
|
|
|
|
backgroundColor = isMessageReceived(message)
|
|
|
|
? 'primary.dark'
|
|
|
|
: 'primary.main'
|
|
|
|
} else {
|
|
|
|
backgroundColor = 'grey.700'
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="Message block">
|
|
|
|
<Typography
|
|
|
|
variant="body1"
|
|
|
|
sx={{
|
|
|
|
backgroundColor,
|
|
|
|
margin: 0.5,
|
|
|
|
padding: 1,
|
|
|
|
borderRadius: 6,
|
|
|
|
float: message.authorId === userId ? 'right' : 'left',
|
|
|
|
transition: 'background-color 1s',
|
2022-08-27 19:40:51 -05:00
|
|
|
wordBreak: 'break-all',
|
2022-08-23 21:46:07 -05:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
{message.text}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|