owncast/web/components/chat/ChatUserMessage/ChatUserMessage.tsx

32 lines
1.1 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react';
2022-05-22 16:10:34 +02:00
import { ChatMessage } from '../../../interfaces/chat-message.model';
import { formatTimestamp, formatMessageText } from './messageFmt';
2022-05-22 16:10:34 +02:00
import s from './ChatUserMessage.module.scss';
interface Props {
message: ChatMessage;
showModeratorMenu: boolean;
}
export default function ChatUserMessage({ message, showModeratorMenu }: Props) {
const { body, user, timestamp } = message;
const { displayName, displayColor } = user;
2022-05-22 16:10:34 +02:00
const color = `hsl(${displayColor}, 100%, 70%)`;
const formattedTimestamp = `Sent at ${formatTimestamp(timestamp)}`;
const [formattedMessage, setFormattedMessage] = useState<string>(body);
useEffect(() => {
setFormattedMessage(formatMessageText(body));
}, [message]);
return (
<div className={s.root} style={{ borderColor: color }} title={formattedTimestamp}>
2022-05-22 16:10:34 +02:00
<div className={s.user} style={{ color }}>
{displayName}
</div>
<div className={s.message} dangerouslySetInnerHTML={{ __html: formattedMessage }} />
{showModeratorMenu && <div>Moderator menu</div>}
</div>
);
}