import { memo, useCallback } from 'react' import { Change, CommentOperation } from '../../../../../types/change' import { ReviewPanelMessage } from './review-panel-message' import { useTranslation } from 'react-i18next' import { useThreadsContext } from '../context/threads-context' import AutoExpandingTextArea from '@/shared/components/auto-expanding-text-area' import ReviewPanelResolvedMessage from './review-panel-resolved-message' import { ReviewPanelResolvedCommentThread } from '../../../../../types/review-panel/comment-thread' import useSubmittableTextInput from '../hooks/use-submittable-text-input' import { CommentId } from '../../../../../types/review-panel/review-panel' export const ReviewPanelCommentContent = memo<{ comment: Change isResolved: boolean onEdit?: (commentId: CommentId, content: string) => Promise onReply?: (content: string) => Promise onDelete?: (commentId: CommentId) => Promise onResolve?: () => Promise onLeave?: () => void onEnter?: () => void }>( ({ comment, isResolved, onResolve, onDelete, onEdit, onReply, onLeave, onEnter, }) => { const { t } = useTranslation() const threads = useThreadsContext() const handleSubmit = useCallback( (content, setContent) => onReply?.(content).then(() => setContent('')), [onReply] ) const { handleChange, handleKeyPress, content } = useSubmittableTextInput(handleSubmit) const thread = threads?.[comment.op.t] if (!thread) { return null } return (
{thread.messages.map((message, i) => { const isReply = i !== 0 return (
{isReply && (
)} 1} onResolve={onResolve} onEdit={onEdit} onDelete={onDelete} isThreadResolved={isResolved} />
) })} {isResolved && (
)} {!isResolved && ( )}
) } ) ReviewPanelCommentContent.displayName = 'ReviewPanelCommentContent'