import CommentContent from './comment-content'; import React from 'react'; import { Avatar, Button, LoadingIndicator } from '@tryghost/shade/components'; import { type Comment, useHideComment, useShowComment, useUnpinComment, } from '@tryghost/admin-x-framework/api/comments'; import { CommentHeader } from './comment-header'; import { CommentMenu } from './comment-menu'; import { CommentMetrics } from './comment-metrics'; import { buildThreadLink } from './thread-link'; import { memberAvatarProps } from '@/members/api'; import { Link, useSearchParams } from '@tryghost/admin-x-framework'; import { LucideIcon, cn } from '@tryghost/shade/utils'; function RepliesLine({ hasReplies }: { hasReplies: boolean }) { if (!hasReplies) { return null; } return (
); } interface CommentRowProps { comment: Comment; dislikesEnabled: boolean; isReply?: boolean; isSelectedComment?: boolean; selectedCommentId?: string; } function CommentRow({ comment, dislikesEnabled, isReply = false, isSelectedComment = false, selectedCommentId, }: CommentRowProps) { const [searchParams] = useSearchParams(); const { mutate: hideComment } = useHideComment(); const { mutate: showComment } = useShowComment(); const { mutate: unpinComment } = useUnpinComment(); // Check replies array for loaded objects, or count.direct_replies for unloaded // TODO: remove count.replies fallback once backend is fully rolled out const hasReplies = (comment.replies?.length ?? 0) > 0 || (comment.count?.direct_replies ?? comment.count?.replies ?? 0) > 0; const containerClassName = !hasReplies || isReply ? 'mb-7' : 'mb-0'; return (
unpinComment({ id: comment.id })} /> {comment.in_reply_to_snippet && isSelectedComment && (
Replied to:  { e.stopPropagation(); }} > {comment.in_reply_to_snippet}
)}
{comment.status === 'published' && ( )} {comment.status === 'hidden' && ( )}
{/* Render nested replies INSIDE the parent comment */} {hasReplies && comment.replies && (
{comment.replies.map((reply) => ( ))}
)}
); } interface CommentThreadListProps { selectedComment: Comment; dislikesEnabled: boolean; replies: Comment[]; selectedCommentId: string; fetchNextPage: () => void; hasNextPage?: boolean; isFetchingNextPage: boolean; } const CommentThreadList: React.FC = ({ selectedComment, dislikesEnabled, replies, selectedCommentId, fetchNextPage, hasNextPage, isFetchingNextPage, }) => { // All replies are children of the selected comment (flat structure from API) const commentWithReplies: Comment = { ...selectedComment, replies }; return (
{hasNextPage && (
)}
); }; export default CommentThreadList;