'use client'; import { useRef } from 'react'; import { formatPetAge, isBirthdayToday } from '@/app/lib/petAge'; import { timeAgo } from "@/lib/time"; export type PostCardData = { id: number; petName: string; petType: 'Hund' | 'Katze'; authorName: string; createdAt: string; text: string; likesCount: number; commentsCount: number; petbirthDate?: string; }; type PostCardProps = { post: PostCardData; isDiscovery?: boolean onOpenPreview: (post: PostCardData) => void; onCommentClick?: (post: PostCardData) => void; }; export default function PostCard({ post, onOpenPreview, onCommentClick, isDiscovery, }: PostCardProps) { const likeRef = useRef(null); const commentRef = useRef(null); const isBirthday = post.petBirthDate && isBirthdayToday(post.petBirthDate); function animate( ref: React.RefObject, animation: string ) { if (!ref.current) return; const el = ref.current; el.style.animation = animation; el.addEventListener( 'animationend', () => { el.style.animation = ''; }, { once: true } ); } return (
{/* Klickbarer Bereich → Preview */}
onOpenPreview(post)} >
{isDiscovery && (
)}
{post.petName} · {post.petType} {post.petBirthDate && ` · ${formatPetAge(post.petBirthDate)}`} · {post.authorName} · {timeAgo(post.createdAt)} {isBirthday && ( 🎂 )}

{post.text}

{/* Interaktionen */}
); }