import Link from 'next/link'; import { useEffect, useState, forwardRef, useContext, Fragment } from 'react'; import date from 'date-and-time'; import htmlParser from 'html-react-parser'; import { UserContext } from '../../../contexts/UserContext'; import { API_URL } from '../../../utils/config/config'; import ReactMarkdown from 'react-markdown'; import CodeBlock from "../../CodeBlock"; import api from '../../../utils/api'; import './CommentCard.css'; const CommentCard = forwardRef((props, ref) => { const { isAuth, user } = useContext(UserContext); const [isEditing, setEditing] = useState(false); const [editInput, setEditInput] = useState(""); const [message, setMessage] = useState(""); useEffect(() => { setEditInput(props.message); }, []); const deleteCommentById = async () => { props.manageComment.setLoadingComments(true); if (isAuth && user.token != undefined) { try { await api.delete(`/comments/${props.id}`, { headers: { 'Authorization': user.token } }); const newCommentsData = { ...props.manageComment.commentsData }; const commentIndex = newCommentsData.rows.findIndex((value) => value.id === props.id); newCommentsData.rows.splice(commentIndex, 1); props.manageComment.setCommentsData({ hasMore: props.manageComment.commentsData.hasMore, rows: newCommentsData.rows }); } catch {} } props.manageComment.setLoadingComments(false); } const handleChange = (event) => { setEditInput(event.target.value); } const handleSubmit = (event) => { event.preventDefault(); api.put(`/comments/${props.id}`, { message: editInput }, { headers: { 'Authorization': user.token } }) .then((_response) => { setEditing(false); }) .catch((error) => { setMessage(`
Erreur: ${error.response.data.message}
`); }); } const editComment = () => { setEditing(true); setMessage(""); } return (