From 124e12626c2a81231332941b48b9e463ea94ea75 Mon Sep 17 00:00:00 2001 From: "cto-new[bot]" <140088366+cto-new[bot]@users.noreply.github.com> Date: Sun, 4 Jan 2026 08:42:43 +0000 Subject: [PATCH] fix(social-state): reset per-post likes and comments when switching posts --- pages/Karya.tsx | 10 ++++++++++ pages/Profile.tsx | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/pages/Karya.tsx b/pages/Karya.tsx index 9d945d0..6696fec 100644 --- a/pages/Karya.tsx +++ b/pages/Karya.tsx @@ -357,6 +357,16 @@ export const Karya = () => { setActiveSlide(0); }, [selectedId]); + // CRITICAL: Clear social states when switching posts to prevent showing wrong comments/likes + useEffect(() => { + // Reset to empty states when selectedId changes + setLikesCount(0); + setIsLiked(false); + setComments([]); + setNewComment(''); + setIsSubmittingComment(false); + }, [selectedId]); + const handleToggleLike = async () => { if (!user || !selectedId) { alert('Silakan login untuk menyukai karya ini.'); diff --git a/pages/Profile.tsx b/pages/Profile.tsx index 7166252..fd3f17d 100644 --- a/pages/Profile.tsx +++ b/pages/Profile.tsx @@ -248,6 +248,16 @@ export const Profile = () => { } }, [socialData]); + // CRITICAL: Clear social states when switching posts to prevent showing wrong comments/likes + useEffect(() => { + // Reset to empty states when selectedId changes + setLikesCount(0); + setIsLiked(false); + setComments([]); + setNewComment(''); + setIsSubmittingComment(false); + }, [selectedId]); + const handleToggleLike = async () => { if (!user || !selectedId) return; const prevLiked = isLiked;