2026-07-04 23:45:27 +04:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
|
import Box from '@mui/material/Box'
|
2026-07-05 19:50:54 +04:00
|
|
|
import Stack from '@mui/material/Stack'
|
2026-07-04 23:45:27 +04:00
|
|
|
import Avatar from '@mui/material/Avatar'
|
|
|
|
|
import Typography from '@mui/material/Typography'
|
|
|
|
|
import Chip from '@mui/material/Chip'
|
|
|
|
|
import Link from 'next/link'
|
2026-07-05 19:50:54 +04:00
|
|
|
import {format} from 'date-fns'
|
|
|
|
|
import {fr} from 'date-fns/locale'
|
2026-07-05 19:35:40 +04:00
|
|
|
import {Mastodon} from '@icons-pack/react-simple-icons'
|
2026-07-04 23:45:27 +04:00
|
|
|
|
|
|
|
|
function formatAuteur(commentaire) {
|
|
|
|
|
if (commentaire.origine === 'activitypub') {
|
|
|
|
|
return commentaire.auteurNom || commentaire.auteurHandle || 'Yon moun'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commentaire.user?.username || 'Anonim'
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-05 19:50:54 +04:00
|
|
|
function formatDat(commentaire) {
|
|
|
|
|
if (!commentaire.datePublication) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-05 20:17:35 +04:00
|
|
|
return format(new Date(commentaire.datePublication), 'Pp', {locale: fr})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const MENTION_REGEX = /(?:@[\w.-]+){1,2}/g
|
|
|
|
|
|
|
|
|
|
function metanValèMansyon(contenu) {
|
|
|
|
|
const mansyon = contenu.match(MENTION_REGEX) || []
|
|
|
|
|
return contenu.split(MENTION_REGEX).flatMap((moso, index) => (
|
|
|
|
|
mansyon[index] ? [
|
|
|
|
|
moso,
|
|
|
|
|
<Box key={index} component='span' sx={{color: 'primary.main', fontWeight: 700}}>
|
|
|
|
|
{mansyon[index]}
|
|
|
|
|
</Box>
|
|
|
|
|
] : [moso]
|
|
|
|
|
))
|
2026-07-05 19:50:54 +04:00
|
|
|
}
|
|
|
|
|
|
2026-07-04 23:45:27 +04:00
|
|
|
export default function Komante({commentaires}) {
|
|
|
|
|
if (!commentaires || commentaires.length === 0) {
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box sx={{maxWidth: 700, margin: '2em auto 0'}}>
|
|
|
|
|
<Typography gutterBottom variant='h6'>
|
2026-07-05 19:50:54 +04:00
|
|
|
Komantè ({commentaires.length})
|
2026-07-04 23:45:27 +04:00
|
|
|
</Typography>
|
2026-07-05 19:50:54 +04:00
|
|
|
<Stack spacing={1.5}>
|
|
|
|
|
{commentaires.map(commentaire => {
|
|
|
|
|
const auteur = formatAuteur(commentaire)
|
|
|
|
|
const estFedere = commentaire.origine === 'activitypub'
|
|
|
|
|
const dat = formatDat(commentaire)
|
2026-07-04 23:45:27 +04:00
|
|
|
|
2026-07-05 19:50:54 +04:00
|
|
|
return (
|
|
|
|
|
<Box
|
|
|
|
|
key={commentaire.id}
|
|
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
gap: 1.5,
|
|
|
|
|
p: 2,
|
|
|
|
|
borderRadius: 2,
|
|
|
|
|
bgcolor: 'action.hover'
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<Avatar src={commentaire.auteurAvatarUrl} alt={auteur} />
|
|
|
|
|
<Box sx={{flex: 1, minWidth: 0}}>
|
2026-07-05 20:17:35 +04:00
|
|
|
<Stack direction='row' alignItems='center' flexWrap='wrap' rowGap={0.5}>
|
2026-07-05 19:50:54 +04:00
|
|
|
<Stack direction='row' alignItems='center' spacing={1}>
|
|
|
|
|
<Typography variant='subtitle2' component='div'>
|
|
|
|
|
{estFedere && commentaire.auteurProfilUrl ? (
|
|
|
|
|
<Link href={commentaire.auteurProfilUrl} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
{auteur}
|
|
|
|
|
</Link>
|
|
|
|
|
) : auteur}
|
|
|
|
|
</Typography>
|
|
|
|
|
{estFedere && (
|
|
|
|
|
<Chip
|
|
|
|
|
label='Mastodon'
|
|
|
|
|
size='small'
|
|
|
|
|
icon={<Mastodon size={14} color='#6364FF' title='' />}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
|
|
|
|
{dat && (
|
2026-07-05 20:17:35 +04:00
|
|
|
<Typography variant='caption' color='text.secondary' sx={{ml: 'auto', pl: 2}}>
|
2026-07-05 19:50:54 +04:00
|
|
|
{dat}
|
|
|
|
|
</Typography>
|
|
|
|
|
)}
|
|
|
|
|
</Stack>
|
2026-07-05 20:17:35 +04:00
|
|
|
<Typography variant='body2' sx={{mt: 0.5}}>{metanValèMansyon(commentaire.contenu)}</Typography>
|
2026-07-05 19:50:54 +04:00
|
|
|
{estFedere && commentaire.remoteUrl && (
|
|
|
|
|
<Link href={commentaire.remoteUrl} target='_blank' rel='noopener noreferrer'>
|
|
|
|
|
<Typography variant='caption' color='text.secondary'>Voir sur Mastodon</Typography>
|
2026-07-04 23:45:27 +04:00
|
|
|
</Link>
|
|
|
|
|
)}
|
2026-07-05 19:50:54 +04:00
|
|
|
</Box>
|
2026-07-04 23:45:27 +04:00
|
|
|
</Box>
|
2026-07-05 19:50:54 +04:00
|
|
|
)
|
|
|
|
|
})}
|
|
|
|
|
</Stack>
|
2026-07-04 23:45:27 +04:00
|
|
|
</Box>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Komante.propTypes = {
|
|
|
|
|
commentaires: PropTypes.array
|
|
|
|
|
}
|