import React from "react"; import { useNavigate } from "react-router-dom"; import { postApi } from "../../api/apiService"; import { useAuth } from "../../context/AuthContext"; const HeartIcon = ({ filled }) => ( ); const CommentIcon = () => ( ); const PostCard = ({ post }) => { const navigate = useNavigate(); const { user } = useAuth(); const [isLiked, setIsLiked] = React.useState(post.is_liked || false); const [likesCount, setLikesCount] = React.useState(post.likesCount || 0); const handlePostClick = () => { navigate(`/post/${post.id}`); }; const handleLikeToggle = async (e) => { e.stopPropagation(); try { if (!user) return; if (isLiked) { const response = await postApi.unlikePost(post.id, user.username); setLikesCount(response.data.likes_count); setIsLiked(false); } else { const response = await postApi.likePost(post.id, user.username); setLikesCount(response.data.likes_count); setIsLiked(true); } } catch (error) { console.error("Error occurred while processing like:", error); } }; const handleCommentClick = (e) => { e.stopPropagation(); navigate(`/post/${post.id}`); }; return (
{post.content}