import React, { Fragment } from 'react'; import PropTypes from 'prop-types'; import { translate } from 'react-i18next'; import TimeAgo from 'timeago-react'; import ArticleComment from './ArticleComment'; import { UncontrolledDropdown, DropdownToggle, DropdownMenu, DropdownItem, CustomInput, Button } from 'reactstrap'; import ShareMenu from './ShareMenu'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faFacebook, faInstagram, faPinterest, faReddit, faTumblr, faTwitter, faYoutube } from '@fortawesome/free-brands-svg-icons'; import { faComments, faEye, faFrown, faMeh, faQuoteLeft, faShareAlt, faSmile, faThumbsDown, faThumbsUp } from '@fortawesome/free-solid-svg-icons'; import { capOnlyFirstLetter, convertUTCtoLocal, abbreviateNumber, notNullAndUnd } from '../../../../../common/helper'; import SourceIndexInfoPopup from '../SourceIndexSubTab/SourceIndexInfoPopup'; const icons = { twitter: faTwitter, facebook: faFacebook, instagram: faInstagram, tumblr: faTumblr, pinterest: faPinterest, reddit: faReddit, youtube: faYoutube, POSITIVE: faSmile, NEGATIVE: faFrown, NEUTRAL: faMeh }; const colors = { POSITIVE: '#3ac47d', NEGATIVE: '#FC3939', NEUTRAL: '#868e96', twitter: '#1DA1F2', facebook: '#4267B2', reddit: '#FF5700', instagram: '#8a3ab9', tumblr: '#34526F', pinterest: '#E60023', youtube: '#FF0000' }; export class Article extends React.Component { constructor() { super(); this.state = { shareMenu: false, imgErr: false, sourceModal: false }; this.elemDesc = React.createRef(); } selectArticle = () => { this.props.selectArticle(this.props.article); }; showEmailPopup = () => { this.props.showEmailPopup([this.props.article]); }; showCommentPopup = () => { this.props.showCommentPopup(this.props.article); }; showDeletePopup = () => { this.props.showDeletePopup([this.props.article]); }; showClipPopup = () => { this.props.showClipPopup([this.props.article]); }; toggleShareMenu = () => { this.setState((prev) => ({ shareMenu: !prev.shareMenu })); }; loadMoreComments = () => { const { loadMoreComments, article: { id: articleId, comments: { count: offset } } } = this.props; loadMoreComments(articleId, offset); }; readLater = () => { this.props.readArticleLater(this.props.article); }; onImgError = () => { this.setState({ imgErr: true }); }; toggleSourceModal = () => { this.setState((prev) => ({ sourceModal: !prev.sourceModal })); }; render() { const { article, t, i18n, showCommentPopup, deleteComment } = this.props; let { comments, id, source, sentiment, permalink, publisher, title, image, author, content, published, mentions, tags, likes, dislikes, views, shares, categories } = article; const { imgErr } = this.state; const { data: commentsData, count: commentsCount, // should get real post comment count totalCount: commentsTotalCount } = comments; const isArticleChosen = !!this.props.selectedArticles.find( (item) => item.id === id ); const offsetWidth = this.elemDesc && this.elemDesc.current && this.elemDesc.current.offsetWidth; const hasRightCounters = notNullAndUnd(likes) || notNullAndUnd(dislikes) || commentsCount || // add not null and undefined when counter shows notNullAndUnd(views) || notNullAndUnd(shares) || notNullAndUnd(mentions); const isTwitter = source.siteType === 'twitter'; const isInstagram = source.siteType === 'instagram'; let username; if (isTwitter) { username = author.link && author.link.match( /^https?:\/\/(www\.)?twitter\.com\/(#!\/)?([^\/]+)(\/\w+)*$/ ); username = username && username[3]; } if (isInstagram) { username = author.link && author.link.match( /(?:(?:http|https):\/\/)?(?:www\.)?(?:instagram\.com|instagr\.am)\/([A-Za-z0-9-_\.]+)/ ); username = username && username[1]; } const isRTL = document.documentElement.dir === 'rtl'; return (
{t('searchTab.commentBtn')} {t('searchTab.clipBtn')} {t('searchTab.readLaterBtn')} {t('searchTab.archiveBtn')} {t('searchTab.emailBtn')} {t('searchTab.shareBtn')} {t('searchTab.deleteBtn')}
{source.siteType && ( )} {sentiment && ( )}

{title && ( {title} )}

{image && !imgErr && (!title && permalink ? ( ) : ( ))}
{author.name ? ( author.link ? ( {username ? `@${username}` : author.name} ) : (

{author.name}

) ) : null} {!title && permalink ? (

) : (

)}
{tags && tags.length && tags.length > 0 && (
{t('searchTab.tags')}: {tags.join(', ')}
)} {categories && categories.length > 0 && (

{t('searchTab.categories')}:{' '} {categories.join(', ')}

)}
{published && ( | )} {source.type && ( {capOnlyFirstLetter(source.type)} | )} {source.country && ( {source.country} | )} {publisher && ( | )} {source.title && ( {publisher ? ( {source.title} ) : ( )} )}
{hasRightCounters && (
{notNullAndUnd(likes) && (

{abbreviateNumber(likes)}

)} {notNullAndUnd(dislikes) && (

{abbreviateNumber(dislikes)}

)} {/* {notNullAndUnd(commentsCount) && ( Add above line when real comment counts are visible */} {commentsCount ? (

{abbreviateNumber(commentsCount)}

) : ( '' )} {notNullAndUnd(views) && (

{abbreviateNumber(views)}

)} {notNullAndUnd(shares) && (

{abbreviateNumber(shares)}

)} {notNullAndUnd(mentions) && (

{abbreviateNumber(mentions)}

)}
)}
{commentsData && commentsData.length > 0 && (
{commentsData.map((comment) => { return ( ); })} {commentsCount < commentsTotalCount && ( )}
)} {this.state.shareMenu && ( )} {this.state.sourceModal && ( )}
); } } Article.propTypes = { article: PropTypes.object.isRequired, selectedArticles: PropTypes.array.isRequired, selectArticle: PropTypes.func.isRequired, showEmailPopup: PropTypes.func.isRequired, showDeletePopup: PropTypes.func.isRequired, showCommentPopup: PropTypes.func.isRequired, showClipPopup: PropTypes.func.isRequired, deleteComment: PropTypes.func.isRequired, readArticleLater: PropTypes.func.isRequired, loadMoreComments: PropTypes.func.isRequired, showShareMenu: PropTypes.func.isRequired, i18n: PropTypes.object.isRequired, t: PropTypes.func.isRequired }; export default translate(['tabsContent'], { wait: true })(Article);