/* eslint-disable react/no-danger */ import { FC, useEffect, useState } from 'react'; import he from 'he'; import cn from 'classnames'; import { Tooltip } from 'antd'; import { LinkOutlined } from '@ant-design/icons'; import { useRecoilValue } from 'recoil'; import dynamic from 'next/dynamic'; import styles from './ChatUserMessage.module.scss'; import { formatTimestamp } from './messageFmt'; import { ChatMessage } from '../../../interfaces/chat-message.model'; import { ChatUserBadge } from '../ChatUserBadge/ChatUserBadge'; import { accessTokenAtom } from '../../stores/ClientConfigStore'; // Lazy loaded components const ChatModerationActionMenu = dynamic(() => import('../ChatModerationActionMenu/ChatModerationActionMenu').then( mod => mod.ChatModerationActionMenu, ), ); const Highlight = dynamic(() => import('react-highlighter-ts').then(mod => mod.Highlight)); export type ChatUserMessageProps = { message: ChatMessage; showModeratorMenu: boolean; highlightString: string; sentBySelf: boolean; sameUserAsLast: boolean; isAuthorModerator: boolean; isAuthorAuthenticated: boolean; }; export const ChatUserMessage: FC = ({ message, highlightString, showModeratorMenu, sentBySelf, // Move the border to the right and render a background sameUserAsLast, isAuthorModerator, isAuthorAuthenticated, }) => { const { id: messageId, body, user, timestamp } = message; const { id: userId, displayName, displayColor } = user; const accessToken = useRecoilValue(accessTokenAtom); const color = `var(--theme-color-users-${displayColor})`; const formattedTimestamp = `Sent ${formatTimestamp(timestamp)}`; const [formattedMessage, setFormattedMessage] = useState(body); const badgeNodes = []; if (isAuthorModerator) { badgeNodes.push(); } if (isAuthorAuthenticated) { badgeNodes.push( } userColor={displayColor} />, ); } // TODO: Find a solution to get rid of or replace "he" library since // it's overly large for only use in this one place. useEffect(() => { setFormattedMessage(he.decode(body)); }, [message]); return (
{!sameUserAsLast && (
{displayName} {badgeNodes}
)}
{showModeratorMenu && (
)}
); };