/* eslint-disable max-statements */ import NextImage from 'next/image'; import Script from 'next/script'; import { type FC, useCallback, useState } from 'react'; import { useIntl } from 'react-intl'; import type { Comment as CommentSchema, WithContext } from 'schema-dts'; import type { SingleComment } from '../../../types'; import { useSettings } from '../../../utils/hooks'; import { Button, Link, Time } from '../../atoms'; import { Card, CardActions, CardBody, CardCover, CardFooter, CardHeader, CardMeta, CardTitle, } from '../../molecules'; import { CommentForm, type CommentFormProps } from '../forms'; import styles from './comment.module.scss'; export type UserCommentProps = Pick< SingleComment, 'approved' | 'content' | 'id' | 'meta' | 'parentId' > & Pick & { /** * Enable or disable the reply button. Default: true. */ canReply?: boolean; }; /** * UserComment component * * Render a single comment. */ export const UserComment: FC = ({ approved, canReply = true, content, id, meta, Notice, parentId, saveComment, ...props }) => { const intl = useIntl(); const { website } = useSettings(); const [isReplying, setIsReplying] = useState(false); const handleReply = useCallback( () => setIsReplying((prevState) => !prevState), [] ); if (!approved) { return (
{intl.formatMessage({ defaultMessage: 'This comment is awaiting moderation...', description: 'Comment: awaiting moderation', id: '6a1Uo6', })}
); } const { author, date } = meta; const buttonLabel = isReplying ? intl.formatMessage({ defaultMessage: 'Cancel reply', description: 'Comment: cancel reply button', id: 'LCorTC', }) : intl.formatMessage({ defaultMessage: 'Reply', description: 'Comment: reply button', id: 'hzHuCc', }); const formTitle = intl.formatMessage({ defaultMessage: 'Leave a reply', description: 'Comment: comment form title', id: '2fD5CI', }); const commentSchema: WithContext = { '@context': 'https://schema.org', '@id': `${website.url}/#comment-${id}`, '@type': 'Comment', parentItem: parentId ? { '@id': `${website.url}/#comment-${parentId}` } : undefined, about: { '@type': 'Article', '@id': `${website.url}/#article` }, author: { '@type': 'Person', name: author.name, image: author.avatar?.src, url: author.website, }, creator: { '@type': 'Person', name: author.name, image: author.avatar?.src, url: author.website, }, dateCreated: date, datePublished: date, text: content, }; return ( <>