feat: [closes #53] display message timestamps

This commit is contained in:
Jeremy Kahn 2022-10-29 14:20:56 -05:00
parent 33f85fc8aa
commit 02a2e53b64

View File

@ -1,5 +1,6 @@
import { HTMLAttributes } from 'react' import { HTMLAttributes } from 'react'
import Box from '@mui/material/Box' import Box from '@mui/material/Box'
import Tooltip from '@mui/material/Tooltip'
import Typography, { TypographyProps } from '@mui/material/Typography' import Typography, { TypographyProps } from '@mui/material/Typography'
import Link, { LinkProps } from '@mui/material/Link' import Link, { LinkProps } from '@mui/material/Link'
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
@ -72,6 +73,8 @@ const componentMap = {
}, },
} }
const spaceNeededForSideDateTooltip = 850
export const Message = ({ message, showAuthor, userId }: MessageProps) => { export const Message = ({ message, showAuthor, userId }: MessageProps) => {
let backgroundColor: string let backgroundColor: string
@ -96,6 +99,17 @@ export const Message = ({ message, showAuthor, userId }: MessageProps) => {
<PeerNameDisplay>{message.authorId}</PeerNameDisplay> <PeerNameDisplay>{message.authorId}</PeerNameDisplay>
</Typography> </Typography>
)} )}
<Tooltip
placement={
window.innerWidth >= spaceNeededForSideDateTooltip ? 'left' : 'top'
}
title={String(
Intl.DateTimeFormat(undefined, {
dateStyle: 'short',
timeStyle: 'short',
}).format(message.timeSent)
)}
>
<Box <Box
sx={{ sx={{
color: 'primary.contrastText', color: 'primary.contrastText',
@ -117,6 +131,7 @@ export const Message = ({ message, showAuthor, userId }: MessageProps) => {
{message.text} {message.text}
</Markdown> </Markdown>
</Box> </Box>
</Tooltip>
</Box> </Box>
) )
} }