'use client'
import PropTypes from 'prop-types'
import Box from '@mui/material/Box'
import Stack from '@mui/material/Stack'
import Avatar from '@mui/material/Avatar'
import Typography from '@mui/material/Typography'
import Chip from '@mui/material/Chip'
import Link from 'next/link'
import {Mastodon} from '@icons-pack/react-simple-icons'
function formatAuteur(commentaire) {
if (commentaire.origine === 'activitypub') {
return commentaire.auteurNom || commentaire.auteurHandle || 'Yon moun'
}
return commentaire.user?.username || 'Anonim'
}
function formatDat(commentaire) {
if (!commentaire.datePublication) {
return null
}
return new Intl.DateTimeFormat(undefined, {dateStyle: 'short', timeStyle: 'short'})
.format(new Date(commentaire.datePublication))
}
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,
{mansyon[index]}
] : [moso]
))
}
export default function Komante({commentaires}) {
if (!commentaires || commentaires.length === 0) {
return null
}
return (
Komantè ({commentaires.length})
{commentaires.map(commentaire => {
const auteur = formatAuteur(commentaire)
const estFedere = commentaire.origine === 'activitypub'
const dat = formatDat(commentaire)
return (
{estFedere && commentaire.auteurProfilUrl ? (
{auteur}
) : auteur}
{estFedere && (
}
/>
)}
{dat && (
{dat}
)}
{metanValèMansyon(commentaire.contenu)}
{estFedere && commentaire.remoteUrl && (
Voir sur Mastodon
)}
)
})}
)
}
Komante.propTypes = {
commentaires: PropTypes.array
}