From dfa64eccb41a89d4866efe7ac20c707791c07750 Mon Sep 17 00:00:00 2001 From: glpshchn <464976@niuitmo.ru> Date: Thu, 4 Dec 2025 23:53:54 +0300 Subject: [PATCH] Update files --- frontend/src/components/CommentsModal.jsx | 34 +++++++++++------------ 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/frontend/src/components/CommentsModal.jsx b/frontend/src/components/CommentsModal.jsx index 800bce0..9145094 100644 --- a/frontend/src/components/CommentsModal.jsx +++ b/frontend/src/components/CommentsModal.jsx @@ -1,4 +1,4 @@ -import { useState, useEffect } from 'react' +import { useState, useEffect, useCallback } from 'react' import { createPortal } from 'react-dom' import { X, Send } from 'lucide-react' import { commentPost, getPosts } from '../utils/api' @@ -10,20 +10,17 @@ export default function CommentsModal({ post, onClose, onUpdate }) { const [comment, setComment] = useState('') const [loading, setLoading] = useState(false) const [comments, setComments] = useState([]) - const [fullPost, setFullPost] = useState(post) + const [fullPost, setFullPost] = useState(null) const [loadingPost, setLoadingPost] = useState(false) // Загрузить полные данные поста с комментариями - useEffect(() => { - if (post?._id) { - loadFullPost() - } else { - setFullPost(post) + const loadFullPost = useCallback(async () => { + if (!post?._id) { + setFullPost(post || null) setComments(post?.comments || []) + return } - }, [post?._id]) - - const loadFullPost = async () => { + try { setLoadingPost(true) const response = await getPosts() @@ -44,11 +41,18 @@ export default function CommentsModal({ post, onClose, onUpdate }) { } finally { setLoadingPost(false) } - } + }, [post]) - // Проверка на существование поста + useEffect(() => { + if (post) { + setFullPost(post) + setComments(post.comments || []) + loadFullPost() + } + }, [post, loadFullPost]) + + // Проверка на существование поста ПОСЛЕ хуков if (!post) { - console.error('[CommentsModal] Post is missing') return null } @@ -95,10 +99,6 @@ export default function CommentsModal({ post, onClose, onUpdate }) { } } - if (!post) { - return null - } - return createPortal(