2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-11-07 05:21:29 +00:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-04-29 03:24:35 +01:00
|
|
|
import { urlRegex } from '../features/ui/util/url_regex'
|
2020-11-07 05:21:29 +00:00
|
|
|
import { DEFAULT_REL } from '../constants'
|
2020-04-04 00:18:26 +01:00
|
|
|
import Button from './button'
|
|
|
|
import DotTextSeperator from './dot_text_seperator'
|
|
|
|
import RelativeTimestamp from './relative_timestamp'
|
|
|
|
import Text from './text'
|
|
|
|
|
2020-11-07 05:21:29 +00:00
|
|
|
class TrendsItem extends ImmutablePureComponent {
|
2020-04-04 00:18:26 +01:00
|
|
|
|
2020-11-07 05:21:29 +00:00
|
|
|
render() {
|
|
|
|
const { trend } = this.props
|
2020-04-04 00:18:26 +01:00
|
|
|
|
2020-11-07 05:21:29 +00:00
|
|
|
if (!trend) return null
|
2020-04-04 00:18:26 +01:00
|
|
|
|
2020-11-07 05:21:29 +00:00
|
|
|
const title = trend.get('title')
|
|
|
|
const url = trend.get('trends_url')
|
2020-04-04 00:18:26 +01:00
|
|
|
|
2020-07-02 03:39:43 +01:00
|
|
|
if (!title || !url) return null
|
2020-11-07 05:21:29 +00:00
|
|
|
|
|
|
|
let correctedDescription = trend.get('description')
|
2020-07-02 03:39:43 +01:00
|
|
|
correctedDescription = correctedDescription.length >= 120 ? `${correctedDescription.substring(0, 120).trim()}...` : correctedDescription
|
2020-04-28 06:33:58 +01:00
|
|
|
const descriptionHasLink = correctedDescription.match(urlRegex)
|
|
|
|
|
2020-04-04 00:18:26 +01:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
noClasses
|
2020-07-02 03:39:43 +01:00
|
|
|
href={url}
|
2020-04-07 02:53:23 +01:00
|
|
|
target='_blank'
|
2020-04-29 23:32:49 +01:00
|
|
|
rel={DEFAULT_REL}
|
2020-11-07 05:21:29 +00:00
|
|
|
className={[_s.d, _s.noUnderline, _s.px15, _s.pt10, _s.pb5, _s.borderBottom1PX, _s.borderColorSecondary, _s.bgSubtle_onHover].join(' ')}
|
2020-04-04 00:18:26 +01:00
|
|
|
>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexNormal, _s.pb5].join(' ')}>
|
|
|
|
<div className={_s.d}>
|
2020-04-04 00:18:26 +01:00
|
|
|
<Text size='medium' color='primary' weight='bold'>
|
2020-11-07 05:21:29 +00:00
|
|
|
{title}
|
2020-04-04 00:18:26 +01:00
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
|
2020-04-07 02:53:23 +01:00
|
|
|
{
|
2020-04-24 04:17:27 +01:00
|
|
|
!!correctedDescription && !descriptionHasLink &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.maxH56PX, _s.overflowHidden, _s.pt5, _s.mb5].join(' ')}>
|
2020-04-07 02:53:23 +01:00
|
|
|
<Text size='small' color='secondary'>
|
|
|
|
{correctedDescription}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
}
|
2020-11-07 05:21:29 +00:00
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.flexRow].join(' ')}>
|
2020-04-04 00:18:26 +01:00
|
|
|
<Text color='secondary' size='small'>
|
2020-11-07 05:21:29 +00:00
|
|
|
{trend.get('feed_base_url')}
|
2020-04-04 00:18:26 +01:00
|
|
|
</Text>
|
|
|
|
<DotTextSeperator />
|
|
|
|
<Text color='secondary' size='small' className={_s.ml5}>
|
2020-11-07 05:21:29 +00:00
|
|
|
trends.gab.com
|
2020-04-04 00:18:26 +01:00
|
|
|
</Text>
|
|
|
|
<DotTextSeperator />
|
2020-11-07 05:21:29 +00:00
|
|
|
<Text color='secondary' size='small' className={_s.ml5}>
|
|
|
|
<RelativeTimestamp timestamp={trend.get('publish_date')} />
|
2020-04-04 00:18:26 +01:00
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
2020-11-07 05:21:29 +00:00
|
|
|
TrendsItem.propTypes = {
|
|
|
|
trend: ImmutablePropTypes.map,
|
2020-08-18 01:57:35 +01:00
|
|
|
}
|
|
|
|
|
2020-11-07 05:21:29 +00:00
|
|
|
export default TrendsItem
|