import { FC, HTMLAttributes, memo } from 'react'; import classNames from 'classnames'; import { parseISO } from 'date-fns'; import { NEW_COMMENT_CLASSNAME } from '~/constants/comment'; import { CommentWrapper } from '~/containers/comments/CommentWrapper'; import { IComment, ICommentGroup, IFile } from '~/types'; import { CommendDeleted } from '../../../../../components/node/CommendDeleted'; import { getCommentId } from '../../../../../constants/dom/links'; import { CommentContent } from './components/CommentContent'; import { CommentDistance } from './components/CommentDistance'; import styles from './styles.module.scss'; type Props = HTMLAttributes & { nodeId: number; isEmpty?: boolean; isLoading?: boolean; group: ICommentGroup; isSame?: boolean; canEdit?: boolean; canLike?: boolean; highlighted?: boolean; saveComment: (data: IComment) => Promise; onDelete: (id: IComment['id'], isLocked: boolean) => void; onLike: (id: IComment['id'], isLiked: boolean) => void; onShowImageModal: (images: IFile[], index: number) => void; }; const Comment: FC = memo( ({ group, nodeId, isEmpty, isSame, isLoading, className, highlighted, canEdit, canLike, onDelete, onLike, onShowImageModal, saveComment, ...props }) => { return (
{group.comments.map((comment, index) => { if (comment.deleted_at) { return ( ); } const prefix = Math.abs(group.distancesInDays[index]) > 14 && ( 0 && group.comments[index - 1]?.created_at ? parseISO(group.comments[index - 1].created_at!) : undefined } /> ); return ( <> onLike(comment.id, !comment.liked)} onDelete={(val: boolean) => onDelete(comment.id, val)} onShowImageModal={onShowImageModal} key={comment.id} /> ); })}
); }, ); export { Comment };