import React from 'react'; import { Link } from 'react-router-dom'; import { ArrowUp, ArrowDown, MessageSquare } from 'lucide-react'; import { formatDistanceToNow } from 'date-fns'; import { Post } from '@/types/forum'; import { useForum } from '@/contexts/useForum'; import { useAuth } from '@/contexts/useAuth'; import { RelevanceIndicator } from '@/components/ui/relevance-indicator'; import { AuthorDisplay } from '@/components/ui/author-display'; interface PostCardProps { post: Post; commentCount?: number; } const PostCard: React.FC = ({ post, commentCount = 0 }) => { const { getCellById, votePost, isVoting, userVerificationStatus } = useForum(); const { isAuthenticated, currentUser } = useAuth(); const cell = getCellById(post.cellId); const cellName = cell?.name || 'unknown'; // Calculate vote score const score = post.upvotes.length - post.downvotes.length; // Check user's vote status const userUpvoted = currentUser ? post.upvotes.some(vote => vote.author === currentUser.address) : false; const userDownvoted = currentUser ? post.downvotes.some(vote => vote.author === currentUser.address) : false; // Truncate content for preview const contentPreview = post.content.length > 200 ? post.content.substring(0, 200) + '...' : post.content; const handleVote = async (e: React.MouseEvent, isUpvote: boolean) => { e.preventDefault(); // Prevent navigation when clicking vote buttons if (!isAuthenticated) return; await votePost(post.id, isUpvote); }; return (
{/* Voting column */}
0 ? 'text-cyber-accent' : score < 0 ? 'text-blue-400' : 'text-cyber-neutral' }`} > {score}
{/* Content column */}
{/* Post metadata */}
r/{cellName} Posted by u/ {formatDistanceToNow(new Date(post.timestamp), { addSuffix: true, })} {post.relevanceScore !== undefined && ( <> )}
{/* Post title */}

{post.title}

{/* Post content preview */}

{contentPreview}

{/* Post actions */}
{commentCount} comments
); }; export default PostCard;