import { h } from 'preact'; import PropTypes from 'prop-types'; import { CommentListItem } from './CommentListItem'; import { Button } from '@crayons'; const numberOfCommentsToShow = 2; function linkToCommentsSection(articlePath) { const str = `${articlePath}#comments-container`; return str; } function moreCommentsButton(comments, articlePath, totalCount) { let button = ''; if (totalCount > numberOfCommentsToShow) { button = (
); } return button; } export const CommentsList = ({ comments = [], articlePath, totalCount }) => { if (comments && comments.length > 0) { return (
{comments.slice(0, numberOfCommentsToShow).map((comment) => { return ; })} {moreCommentsButton(comments, articlePath, totalCount)}
); } return ''; }; CommentsList.displayName = 'CommentsList'; Comment.propTypes = PropTypes.shape({ name: PropTypes.string.isRequired, profile_image_90: PropTypes.string.isRequired, published_at_int: PropTypes.number.isRequired, }); CommentsList.propTypes = { comments: PropTypes.arrayOf(Comment.propTypes).isRequired, articlePath: PropTypes.string.isRequired, totalCount: PropTypes.number.isRequired, };