import { HTMLAttributes } from 'react' import Box from '@mui/material/Box' import Typography, { TypographyProps } from '@mui/material/Typography' import Link, { LinkProps } from '@mui/material/Link' import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' import { materialDark } from 'react-syntax-highlighter/dist/esm/styles/prism' // These imports need to be ts-ignored to prevent spurious errors that look // like this: // // Module 'react-markdown' cannot be imported using this construct. The // specifier only resolves to an ES module, which cannot be imported // synchronously. Use dynamic import instead. (tsserver 1471) // // @ts-ignore import Markdown from 'react-markdown' // @ts-ignore import { CodeProps } from 'react-markdown/lib/ast-to-react' // @ts-ignore import remarkGfm from 'remark-gfm' import { Message as IMessage, isMessageReceived } from 'models/chat' import { PeerNameDisplay } from 'components/PeerNameDisplay' import './Message.sass' export interface MessageProps { message: IMessage userId: string } const typographyFactory = (overrides: TypographyProps) => (args: HTMLAttributes) => { return } const linkFactory = (overrides: LinkProps) => (args: HTMLAttributes) => { return } const componentMap = { h1: typographyFactory({ variant: 'h1' }), h2: typographyFactory({ variant: 'h2' }), h3: typographyFactory({ variant: 'h3' }), h4: typographyFactory({ variant: 'h4' }), h5: typographyFactory({ variant: 'h5' }), h6: typographyFactory({ variant: 'h6' }), p: typographyFactory({ variant: 'body1' }), a: linkFactory({ variant: 'body1', underline: 'always', color: 'primary.contrastText', }), // https://github.com/remarkjs/react-markdown#use-custom-components-syntax-highlight code({ node, inline, className, children, style, ...props }: CodeProps) { const match = /language-(\w+)/.exec(className || '') return !inline && match ? ( ) : ( {children} ) }, } export const Message = ({ message, userId }: MessageProps) => { let backgroundColor: string if (message.authorId === userId) { backgroundColor = isMessageReceived(message) ? 'primary.main' : 'primary.light' } else { backgroundColor = 'secondary.main' } return ( {message.authorId} {message.text} ) }