aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/CommentsList/CommentsList.tsx
blob: 6630a03c1e334173906a1d1e84f4919695b16599 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Comment from '@components/Comment/Comment';
import { Comment as CommentData } from '@ts/types/comments';
import { useIntl } from 'react-intl';
import styles from './CommentsList.module.scss';

const CommentsList = ({
  articleId,
  comments,
}: {
  articleId: number;
  comments: CommentData[];
}) => {
  const intl = useIntl();

  const getCommentsList = () => {
    return comments.map((comment) => {
      return (
        <Comment key={comment.id} articleId={articleId} comment={comment} />
      );
    });
  };

  return (
    <>
      <h2 className={styles.title}>
        {intl.formatMessage({
          defaultMessage: 'Comments',
          description: 'CommentsList: Comments section title',
        })}
      </h2>
      {comments.length > 0 ? (
        <ol className={styles.list}>{getCommentsList()}</ol>
      ) : (
        <p className={styles['no-comments']}>
          {intl.formatMessage({
            defaultMessage: 'No comments yet.',
            description: 'CommentsList: No comment message',
          })}
        </p>
      )}
    </>
  );
};

export default CommentsList;