import PropTypes from 'prop-types'; import { h, Fragment } from 'preact'; import { createPortal } from 'preact/compat'; import { FlagUserModal } from '../../packs/flagUserModal'; import { formatDate } from './util'; export const SingleArticle = ({ id, title, publishedAt, cachedTagList, user, key, articleOpened, path, toggleArticle, }) => { const activateToggle = () => toggleArticle(id, title, path); const tagsFormat = (tag, key) => { if (tag) { return ( # {tag} ); } }; const tags = cachedTagList.split(', ').map((tag) => 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, };