import { useCallback, useMemo } from 'react'; import { MarkdownViewer } from '@renderer/components/chat/viewers/MarkdownViewer'; import { MentionableTextarea } from '@renderer/components/ui/MentionableTextarea'; import { useDraftPersistence } from '@renderer/hooks/useDraftPersistence'; import { useMarkCommentsRead } from '@renderer/hooks/useMarkCommentsRead'; import { useStore } from '@renderer/store'; import { formatAgentRole } from '@renderer/utils/formatAgentRole'; import { formatDistanceToNow } from 'date-fns'; import { MessageSquare, Send } from 'lucide-react'; import type { MentionSuggestion } from '@renderer/types/mention'; import type { ResolvedTeamMember, TaskComment } from '@shared/types'; const MAX_COMMENT_LENGTH = 2000; interface TaskCommentsSectionProps { teamName: string; taskId: string; comments: TaskComment[]; members: ResolvedTeamMember[]; } export const TaskCommentsSection = ({ teamName, taskId, comments, members, }: TaskCommentsSectionProps): React.JSX.Element => { const addTaskComment = useStore((s) => s.addTaskComment); const addingComment = useStore((s) => s.addingComment); const commentsRef = useMarkCommentsRead(teamName, taskId, comments); const draft = useDraftPersistence({ key: `taskComment:${teamName}:${taskId}` }); const mentionSuggestions = useMemo( () => members.map((m) => ({ id: m.name, name: m.name, subtitle: formatAgentRole(m.role) ?? formatAgentRole(m.agentType) ?? undefined, color: m.color, })), [members] ); const trimmed = draft.value.trim(); const remaining = MAX_COMMENT_LENGTH - trimmed.length; const canSubmit = trimmed.length > 0 && trimmed.length <= MAX_COMMENT_LENGTH && !addingComment; const handleSubmit = useCallback(async () => { if (!canSubmit) return; try { await addTaskComment(teamName, taskId, trimmed); draft.clearDraft(); } catch { // Error is stored in addCommentError via store } }, [canSubmit, addTaskComment, teamName, taskId, trimmed, draft]); return (
Comments {comments.length > 0 ? ( {comments.length} ) : null}
{comments.length > 0 ? (
{comments.map((comment) => (
m.name === comment.author)?.color ?? 'var(--color-text-secondary)'), }} > {comment.author} {formatDistanceToNow(new Date(comment.createdAt), { addSuffix: true })}
))}
) : null}
{remaining < 200 ? ( {remaining} chars left ) : null} {draft.isSaved ? ( Draft saved ) : null}
} />
); };