import PropTypes from 'prop-types'; import { h, Component } from 'preact'; import { formatDate } from './util'; export default class SingleArticle extends Component { constructor(props) { super(props); this.state = { articleOpened: false, }; } toggleArticle = (e) => { e.preventDefault(); const { id, path } = this.props; const { articleOpened } = this.state; if (articleOpened) { this.setState({ articleOpened: false }); document.getElementById(`article-iframe-${id}`).innerHTML = ''; } else { this.setState({ articleOpened: true }); document.getElementById( `article-iframe-${id}`, ).innerHTML = ``; } }; render() { const { articleOpened } = this.state; const { id, title, publishedAt, cachedTagList, user, key } = this.props; const tags = cachedTagList.split(', ').map((tag) => { if (tag) { return ( # {tag} ); } }); const newAuthorNotification = user.articles_count <= 3 ? '👋 ' : ''; return ( ); } } 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, };