"use client"; import { useAtom } from "jotai"; import { currentUserAtom } from "@/atoms/user/user-query.atoms"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { cn } from "@/lib/utils"; import { CommentComposer } from "../comment-composer/comment-composer"; import { CommentThread } from "../comment-thread/comment-thread"; import type { CommentPanelProps } from "./types"; function getInitials(name: string | null | undefined, email: string): string { if (name) { return name .split(" ") .map((part) => part[0]) .join("") .toUpperCase() .slice(0, 2); } return email[0].toUpperCase(); } export function CommentPanel({ threads, members, membersLoading = false, isLoading = false, onCreateComment, onCreateReply, onEditComment, onDeleteComment, isSubmitting = false, maxHeight, variant = "desktop", }: CommentPanelProps) { const [{ data: currentUser }] = useAtom(currentUserAtom); const handleCommentSubmit = (content: string) => { onCreateComment(content); }; const isMobile = variant === "mobile"; const isInline = variant === "inline"; if (isLoading) { return (
Loading comments...
); } const hasThreads = threads.length > 0; // Ensure minimum usable height for empty state + composer button const minHeight = 180; const effectiveMaxHeight = maxHeight ? Math.max(maxHeight, minHeight) : undefined; return (
{hasThreads && (
{threads.map((thread) => ( ))}
)} {!hasThreads && currentUser && (
{getInitials(currentUser.display_name, currentUser.email)}
{currentUser.display_name ?? currentUser.email}
)}
); }