From 6247c3220662a14bcd8b59187ff7dde337ae3f30 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Mon, 9 Nov 2020 01:34:40 -0600 Subject: [PATCH] Added TrendsCard component MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - TrendsCard component --- .../gabsocial/components/trends_card.js | 165 ++++++++++++++++++ 1 file changed, 165 insertions(+) create mode 100644 app/javascript/gabsocial/components/trends_card.js diff --git a/app/javascript/gabsocial/components/trends_card.js b/app/javascript/gabsocial/components/trends_card.js new file mode 100644 index 00000000..a9615e7c --- /dev/null +++ b/app/javascript/gabsocial/components/trends_card.js @@ -0,0 +1,165 @@ +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 ( +