45 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-08-20 22:23:43 -05:00
import Typography from '@mui/material/Typography'
import { isMessageReceived, UnsentMessage, ReceivedMessage } from 'models/chat'
2022-08-20 22:23:43 -05:00
export interface ChatTranscriptProps {
messageLog: Array<UnsentMessage | ReceivedMessage>
2022-08-21 10:44:01 -05:00
userId: string
2022-08-20 22:23:43 -05:00
}
2022-08-21 10:44:01 -05:00
export const ChatTranscript = ({ messageLog, userId }: ChatTranscriptProps) => {
2022-08-20 22:23:43 -05:00
return (
2022-08-21 10:32:54 -05:00
<div className="ChatTranscript flex flex-col">
{messageLog.map(message => {
let backgroundColor: string
if (message.authorId === userId) {
backgroundColor = isMessageReceived(message)
? 'primary.dark'
: 'primary.main'
} else {
backgroundColor = 'grey.700'
}
return (
<div className="block" key={message.id}>
<Typography
variant="body1"
sx={{
backgroundColor,
margin: 0.5,
padding: 1,
borderRadius: 6,
float: message.authorId === userId ? 'right' : 'left',
transition: 'background-color 1s',
}}
>
{message.text}
</Typography>
</div>
)
})}
2022-08-20 22:23:43 -05:00
</div>
)
}