'use client' import { useState } from 'react' import { useSession } from 'next-auth/react' interface ReviewCardProps { id: string username: string avatarUrl?: string | null content: string rating: number playtimeHours?: number | null upvotes: number downvotes: number userVote?: number | null createdAt: string onVote: (reviewId: string, voteType: 1 | -1) => Promise } export function ReviewCard({ id, username, avatarUrl, content, rating, playtimeHours, upvotes, downvotes, userVote, createdAt, onVote }: ReviewCardProps) { const { data: session } = useSession() const [voting, setVoting] = useState(false) const handleVote = async (voteType: 1 | -1) => { if (!session) return setVoting(true) try { await onVote(id, voteType) } finally { setVoting(false) } } const formatDate = (dateString: string) => { return new Date(dateString).toLocaleDateString('en-US', { year: 'numeric', month: 'short', day: 'numeric' }) } return (
{avatarUrl ? ( {username} ) : ( 👤 )}
{username} {rating}/10 {playtimeHours !== null && playtimeHours !== undefined && ( {playtimeHours}h played )}

{content}

{formatDate(createdAt)} {session && (
)} {!session && ( Sign in to vote )}
) }