'use client' import Link from 'next/link' import { useState } from 'react' import ReactMarkdown from 'react-markdown' import remarkGfm from 'remark-gfm' import { Badge, Button, Card, CardContent, CardFooter, CardHeader, CardTitle } from 'ui' import { markdownComponents } from './markdownComponents' interface Reply { id: string content: string | null author: string | null ts: string | null external_activity_url: string | null } interface RepliesListProps { replies: Reply[] questionAuthor: string | null totalReplyCount?: number } export function RepliesList({ replies, questionAuthor, totalReplyCount }: RepliesListProps) { const [isExpanded, setIsExpanded] = useState(false) const hasMoreThanThree = replies.length > 3 const displayedReplies = isExpanded ? replies : replies.slice(0, 3) if (replies.length === 0) { return null } const displayCount = totalReplyCount || replies.length return (
Replies{' '} ({displayCount}) {displayedReplies.map((reply, index) => { const timestamp = reply.ts ? new Date(reply.ts).toLocaleString() : null const isOP = reply.author === questionAuthor return (
{reply.content || ''}
{reply.author && ( <> {isOP && OP} {reply.author} )} {reply.author && timestamp && ยท} {timestamp && reply.external_activity_url ? ( {timestamp} ) : ( timestamp && {timestamp} )}
) })}
{hasMoreThanThree && ( )}
) }