import { Fragment } from 'react' import { urlRegex } from '../features/ui/util/url_regex' import { CX, DEFAULT_REL, } from '../constants' import Button from './button' import DotTextSeperator from './dot_text_seperator' import RelativeTimestamp from './relative_timestamp' import Text from './text' export default class TrendingItem extends PureComponent { static propTypes = { index: PropTypes.number, isLast: PropTypes.bool, isHidden: PropTypes.bool, title: PropTypes.string, description: PropTypes.string, author: PropTypes.string, url: PropTypes.string, date: PropTypes.string, } static defaultProps = { title: '', description: '', author: '', url: '', date: '', } state = { hovering: false, } handleOnMouseEnter = () => { this.setState({ hovering: true }) } handleOnMouseLeave = () => { this.setState({ hovering: false }) } render() { const { index, isLast, isHidden, title, description, author, url, date, } = this.props const { hovering } = this.state if (!title || !url) return null const correctedTitle = `${title}`.trim() let correctedDescription = description || '' const correctedAuthor = `${author}`.replace('www.', '') correctedDescription = correctedDescription.length >= 120 ? `${correctedDescription.substring(0, 120).trim()}...` : correctedDescription const descriptionHasLink = correctedDescription.match(urlRegex) if (isHidden) { return ( {correctedTitle} {!descriptionHasLink && correctedDescription} {correctedAuthor} ) } const containerClasses = CX({ default: 1, noUnderline: 1, px15: 1, pt10: 1, pb5: 1, borderColorSecondary: !isLast, borderBottom1PX: !isLast, backgroundColorSubtle_onHover: 1, }) const subtitleClasses = CX({ ml5: 1, underline: hovering, }) return ( this.handleOnMouseEnter()} onMouseLeave={() => this.handleOnMouseLeave()} > {correctedTitle} { !!correctedDescription && !descriptionHasLink && {correctedDescription} } {index} {correctedAuthor} { hovering && → } ) } }