gab-social/app/javascript/gabsocial/components/trends_item.js

76 lines
2.4 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
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'
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'
class TrendsItem extends ImmutablePureComponent {
2020-04-04 00:18:26 +01:00
render() {
const { trend } = this.props
2020-04-04 00:18:26 +01:00
if (!trend) return null
2020-04-04 00:18:26 +01:00
const title = trend.get('title')
const url = trend.get('trends_url')
2020-04-04 00:18:26 +01:00
if (!title || !url) return null
let correctedDescription = trend.get('description')
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
href={url}
2020-04-07 02:53:23 +01:00
target='_blank'
2020-04-29 23:32:49 +01:00
rel={DEFAULT_REL}
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
>
<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'>
{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 &&
<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>
}
<div className={[_s.d, _s.flexRow].join(' ')}>
2020-04-04 00:18:26 +01:00
<Text color='secondary' size='small'>
{trend.get('feed_base_url')}
2020-04-04 00:18:26 +01:00
</Text>
<DotTextSeperator />
<Text color='secondary' size='small' className={_s.ml5}>
trends.gab.com
2020-04-04 00:18:26 +01:00
</Text>
<DotTextSeperator />
<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>
)
}
}
TrendsItem.propTypes = {
trend: ImmutablePropTypes.map,
}
export default TrendsItem