import React from 'react'; import timeago from 'timeago.js'; import Linkify from 'react-linkify'; import styles from './CommentList.css'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations.json'; import {Icon} from 'react-mdl'; import {FabButton, Button} from 'coral-ui'; const linkify = new Linkify(); // Render a single comment for the list export default props => { const {comment, author} = props; let authorStatus = author.status; const links = linkify.getMatches(comment.body); return (
  • person {author.displayName || lang.t('comment.anon')} {timeago().format(comment.createdAt || (Date.now() - props.index * 60 * 1000), lang.getLocale().replace('-', '_'))} {comment.flagged ?

    {lang.t('comment.flagged')}

    : null}
    {links ? Contains Link : null}
    {props.actions.map((action, i) => getActionButton(action, i, props))}
    {authorStatus === 'banned' ? {lang.t('comment.banned_user')} : null}
    {comment.body}
  • ); }; // Get the button of the action performed over a comment if any const getActionButton = (action, i, props) => { const {comment, author} = props; const status = comment.status; const flagged = comment.flagged; const banned = (author.status === 'banned'); if (action === 'flag' && (status || flagged === true)) { return null; } if (action === 'ban') { return ( ); } return ( props.onClickAction(props.actionsMap[action].status, comment)} /> ); }; const linkStyles = { backgroundColor: 'rgb(255, 219, 135)', padding: '1px 2px' }; const lang = new I18n(translations);