import PropTypes from 'prop-types'; import { h, Component, Fragment } from 'preact'; import { createPortal } from 'preact/compat'; import { FlagUserModal } from '../../packs/flagUserModal'; import { formatDate } from './util'; export class SingleArticle extends Component { activateToggle = () => { const { id, title, path, toggleArticle } = this.props; toggleArticle(id, title, path); }; tagsFormat = (tag, key) => { if (tag) { return ( # {tag} ); } }; render() { const { id, title, publishedAt, cachedTagList, user, key, articleOpened, path, } = this.props; const tags = cachedTagList.split(', ').map((tag) => { this.tagsFormat(tag, key); }); const newAuthorNotification = user.articles_count <= 3 ? '👋 ' : ''; const modContainer = id ? document.getElementById(`mod-iframe-${id}`) : document.getElementById('mod-container'); return ( {modContainer && createPortal( , document.getElementsByClassName('flag-user-modal-container')[0], )} {title} {tags} {newAuthorNotification} {user.name} {formatDate(publishedAt)} ); } } SingleArticle.propTypes = { id: PropTypes.number.isRequired, title: PropTypes.string.isRequired, path: PropTypes.string.isRequired, publishedAt: PropTypes.string.isRequired, cachedTagList: PropTypes.isRequired, user: PropTypes.isRequired, key: PropTypes.number.isRequired, };