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

68 lines
1.6 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'
}
}))
2022-05-20 02:19:10 +04:00
export default function KomanteList({commentaires}) {
2021-06-26 12:25:50 +02:00
return (
2022-01-19 06:35:04 +04:00
<StyledList className={classes.root}>
2022-05-20 02:19:10 +04:00
{commentaires.map(({id, attributes}) => (
2022-05-05 17:58:05 +04:00
<div key={id}>
2021-06-26 12:25:50 +02:00
<ListItemText
primary={
2022-05-20 02:19:10 +04:00
<Typography gutterBottom style={{textDecoration: 'underline'}} variant='body1'>
<small>{attributes.user.data.attributes.username}</small>
2021-06-26 12:25:50 +02:00
</Typography>
}
/>
<ListItemText
2022-05-20 02:19:10 +04:00
primary={formatJsonString(attributes.contenu)}
2021-06-26 12:25:50 +02:00
secondary={
<Typography gutterBottom style={{marginBlock: 5, fontStyle: 'italic'}} variant='caption' display='block'>
2022-05-20 02:19:10 +04:00
{format(new Date(attributes.datePublication), 'Pp', {locale: fr})}
2021-06-26 12:25:50 +02:00
</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 = {
2022-05-20 02:19:10 +04:00
commentaires: PropTypes.array.isRequired
2021-06-26 12:25:50 +02:00
}