diff --git a/package.json b/package.json index 6b5b631..7635ee9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sociowire-frontend", "private": true, - "version": "0.0.89", + "version": "0.0.90", "type": "module", "scripts": { "dev": "vite --host 0.0.0.0", diff --git a/src/components/Posts/PostDetailModal.jsx b/src/components/Posts/PostDetailModal.jsx index d57af68..9b9a4f2 100644 --- a/src/components/Posts/PostDetailModal.jsx +++ b/src/components/Posts/PostDetailModal.jsx @@ -504,6 +504,7 @@ export default function PostDetailModal({ post, onClose, onPostUpdated, onPostDe const [fullscreen, setFullscreen] = useState(false); const commentsEndRef = useRef(null); + const justCommentedRef = useRef(false); const postId = post?.id || post?._id; const isAuthor = username && (post?.author === username || post?.username === username); const postType = useMemo(() => getPostType(post), [post]); @@ -568,7 +569,13 @@ export default function PostDetailModal({ post, onClose, onPostUpdated, onPostDe }, [postId]); useEffect(() => { refreshComments(true); }, [refreshComments]); - useEffect(() => { if (showComments) commentsEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [comments, showComments]); + useEffect(() => { + // Only scroll to bottom when user just added a comment, not on initial load + if (showComments && justCommentedRef.current) { + commentsEndRef.current?.scrollIntoView({ behavior: "smooth" }); + justCommentedRef.current = false; + } + }, [comments, showComments]); // Handlers const handleLike = useCallback(async () => { @@ -602,6 +609,7 @@ export default function PostDetailModal({ post, onClose, onPostUpdated, onPostDe setCommentSending(true); const tempId = `temp_${Date.now()}`; const newComment = { id: tempId, body, username: username || "You", created_at: new Date().toISOString(), _pending: true }; + justCommentedRef.current = true; setComments(prev => [...prev, newComment]); setCounts(c => ({ ...c, comments: c.comments + 1 })); const res = await createPostComment(postId, body);