2022-08-20 22:23:43 -05:00
|
|
|
import Typography from '@mui/material/Typography'
|
|
|
|
|
2022-08-22 21:57:45 -05:00
|
|
|
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">
|
2022-08-22 21:57:45 -05:00
|
|
|
{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>
|
|
|
|
)
|
|
|
|
}
|