import React, { useState, useEffect } from 'react'; import { currentUser } from '../../services/auth'; import './CommentItem.css'; export default function CommentItem({ comment, author }) { const [imageError, setImageError] = useState(false); const isMe = comment.author_id === currentUser?.id; const displayName = isMe ? (currentUser?.username ? `@${currentUser.username}` : currentUser?.first_name || 'Вы') : (author?.username ? `@${author.username}` : author?.first_name || `Игрок #${comment.author_id}`); const photoUrl = isMe ? currentUser?.photo_url : author?.photo_url; useEffect(() => { setImageError(false); }, [photoUrl]); const dateStr = comment.creation_date ? new Date(comment.creation_date).toLocaleDateString('ru-RU', { day: '2-digit', month: '2-digit', hour: '2-digit', minute: '2-digit', }) : ''; const initial = displayName.replace(/^@/, '')[0]?.toUpperCase() || '?'; return (
{comment.comment_text || comment.commet_text}