Files
pawol.nu/components/komante/komante-list.js
T

68 lines
1.5 KiB
JavaScript
Raw Normal View History

2021-06-26 12:25:50 +02:00
import PropTypes from 'prop-types'
import {format} from 'date-fns'
import {fr} from 'date-fns/locale'
2022-01-19 07:06:26 +04:00
import {styled} from '@mui/material/styles'
2021-06-26 12:25:50 +02:00
import {
Typography,
Divider,
List,
ListItemText
2022-01-19 07:06:26 +04:00
} from '@mui/material'
2021-06-26 12:25:50 +02:00
import {formatJsonString} from '../../lib/utils/format'
2022-01-19 06:35:04 +04:00
const PREFIX = 'komante-list'
const classes = {
root: `${PREFIX}-root`,
inline: `${PREFIX}-inline`
}
const StyledList = styled(List)((
{
theme
}
) => ({
[`&.${classes.root}`]: {
2021-06-26 12:25:50 +02:00
width: '100%',
maxWidth: '36ch',
backgroundColor: theme.palette.background.paper
},
2022-01-19 06:35:04 +04:00
[`& .${classes.inline}`]: {
2021-06-26 12:25:50 +02:00
display: 'inline'
}
}))
export default function KomanteList({komante}) {
return (
2022-01-19 06:35:04 +04:00
<StyledList className={classes.root}>
2022-05-05 17:58:05 +04:00
{komante.map(({id, username, kontni, sentAt}) => (
<div key={id}>
2021-06-26 12:25:50 +02:00
<ListItemText
primary={
<Typography gutterBottom style={{fontWeight: 'bold'}} variant='body1'>
{username}
</Typography>
}
/>
<ListItemText
primary={formatJsonString(kontni)}
secondary={
<Typography gutterBottom style={{marginBlock: 5, fontStyle: 'italic'}} variant='caption' display='block'>
{format(new Date(sentAt), 'Pp', {locale: fr})}
</Typography>
}
/>
<Divider style={{marginBottom: '1em'}} />
</div>
))}
2022-01-19 06:35:04 +04:00
</StyledList>
2021-06-26 12:25:50 +02:00
)
}
KomanteList.propTypes = {
komante: PropTypes.array.isRequired
}