import React from 'react' import PropTypes from 'prop-types' import { connect } from 'react-redux' import ImmutablePureComponent from 'react-immutable-pure-component' import ImmutablePropTypes from 'react-immutable-proptypes' import { openModal } from '../actions/modal' import { changeCompose } from '../actions/compose' import { urlRegex } from '../features/ui/util/url_regex' import { CX, DEFAULT_REL, MODAL_COMPOSE, } from '../constants' import Button from './button' import DotTextSeperator from './dot_text_seperator' import RelativeTimestamp from './relative_timestamp' import Text from './text' import Image from './image' class TrendsCard extends ImmutablePureComponent { handleOnShare = () => { this.props.onOpenComposeModal(this.props.trend.get('trends_url')) } render() { const { trend, viewType, isXS, } = this.props if (!trend) return null const title = trend.get('title') const url = trend.get('trends_url') if (!title || !url) return null let correctedDescription = trend.get('description') correctedDescription = correctedDescription.length >= 120 ? `${correctedDescription.substring(0, 120).trim()}...` : correctedDescription const descriptionHasLink = correctedDescription.match(urlRegex) const containerClasses = CX({ d: 1, w100PC: isXS || viewType === 0, pb10: viewType === 0, w33PC: !isXS && viewType === 1, px10: viewType === 1, py10: viewType === 1, mb5: isXS, }) const innerContainerClasses = CX({ d: 1, flexRow: !isXS && viewType === 0, boxShadowBlock: 1, w100PC: 1, h100PC: 1, radiusSmall: !isXS, overflowHidden: 1, bgPrimary: 1, }) const textContainerClasses = CX({ d: 1, flexNormal: 1, w100PC: viewType === 1, }) let imgWidth, imgHeight = viewType === 1 ? '100%' : '320px' if (viewType === 1) { imgWidth = '100%' imgHeight = '172px' } else { imgWidth = '358px' imgHeight = '232px' } if (isXS) { imgWidth = '100%' imgHeight = '172px' } return (