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-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-08-06 06:12:03 +01:00
|
|
|
import { withRouter } from 'react-router-dom'
|
|
|
|
import isObject from 'lodash.isobject'
|
|
|
|
import queryString from 'query-string'
|
|
|
|
import { fetchGabTrends } from '../actions/gab_trends'
|
|
|
|
import { BREAKPOINT_EXTRA_SMALL } from '../constants'
|
|
|
|
import Block from '../components/block'
|
|
|
|
import Button from '../components/button'
|
|
|
|
import ColumnIndicator from '../components/column_indicator'
|
|
|
|
import Heading from '../components/heading'
|
|
|
|
import Icon from '../components/icon'
|
|
|
|
import Pills from '../components/pills'
|
|
|
|
import Responsive from './ui/util/responsive_component';
|
|
|
|
import TabBar from '../components/tab_bar'
|
|
|
|
import Text from '../components/text'
|
|
|
|
import TrendsItem from '../components/trends_item'
|
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class News extends React.PureComponent {
|
2020-08-06 06:12:03 +01:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
activeDomain: null,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (this.props.location !== prevProps.location) {
|
|
|
|
this.setActiveDomain(this.props.location)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
this.props.onfetchGabTrends()
|
|
|
|
this.setActiveDomain(this.props.location)
|
|
|
|
}
|
|
|
|
|
|
|
|
setActiveDomain(location) {
|
|
|
|
const { search } = location
|
|
|
|
const qp = queryString.parse(search)
|
|
|
|
const domain = qp.domain ? `${qp.domain}`.toLowerCase() : undefined
|
|
|
|
|
|
|
|
if (!!domain) {
|
|
|
|
this.setState({ activeDomain: domain })
|
|
|
|
} else {
|
|
|
|
this.setState({ activeDomain: null })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
render() {
|
2020-08-06 06:12:03 +01:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
isError,
|
|
|
|
isLoading,
|
|
|
|
items,
|
|
|
|
} = this.props
|
|
|
|
const { activeDomain } = this.state
|
|
|
|
|
|
|
|
if (isError || !isObject(items)) {
|
|
|
|
return <div>error</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
let domainExists = !activeDomain
|
|
|
|
let headline, headlineLink
|
|
|
|
let todaysTopTitle
|
|
|
|
let leadHeadlines = []
|
|
|
|
let todaysTop = []
|
|
|
|
let domainTabs = []
|
|
|
|
try {
|
|
|
|
headline = items.headline.title
|
|
|
|
headlineLink = items.headline.href
|
|
|
|
leadHeadlines = items.leadHeadlines
|
|
|
|
|
|
|
|
if (activeDomain) {
|
|
|
|
const domainBlock = items.trackedDomains.find((d) => `${d.domain}`.toLowerCase() === activeDomain)
|
|
|
|
if (domainBlock) domainExists = true
|
2020-08-19 01:22:15 +01:00
|
|
|
|
2020-08-06 06:12:03 +01:00
|
|
|
todaysTop = domainBlock.topUrls
|
|
|
|
todaysTopTitle = domainBlock.title
|
|
|
|
} else {
|
|
|
|
todaysTop = items.trending.topUrls
|
|
|
|
todaysTopTitle = "Today's Top"
|
|
|
|
}
|
|
|
|
|
|
|
|
const domains = items.trackedDomains
|
|
|
|
domainTabs = domains.map((block) => ({
|
|
|
|
title: block.title,
|
2020-08-07 05:09:51 +01:00
|
|
|
to: `/news?domain=${block.domain}`,
|
2020-08-19 01:22:15 +01:00
|
|
|
onClick: () => { },
|
2020-08-06 06:12:03 +01:00
|
|
|
active: activeDomain === `${block.domain}`.toLowerCase(),
|
|
|
|
}))
|
|
|
|
domainTabs = [
|
|
|
|
{
|
|
|
|
title: "Today's Top",
|
2020-08-07 05:09:51 +01:00
|
|
|
to: `/news`,
|
2020-08-19 01:22:15 +01:00
|
|
|
onClick: () => { },
|
2020-08-06 06:12:03 +01:00
|
|
|
active: !activeDomain,
|
|
|
|
},
|
|
|
|
...domainTabs,
|
|
|
|
]
|
|
|
|
} catch (error) {
|
|
|
|
return (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
<Block>
|
|
|
|
<ColumnIndicator type='loading' />
|
|
|
|
</Block>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!domainExists) {
|
|
|
|
return <div>error</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
<Block>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.borderBottom1PX, _s.borderColorSecondary].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
<Responsive min={BREAKPOINT_EXTRA_SMALL}>
|
|
|
|
<TabBar tabs={domainTabs} />
|
|
|
|
</Responsive>
|
|
|
|
<Responsive max={BREAKPOINT_EXTRA_SMALL}>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.w100PC, _s.pt10, _s.pb5].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
<Pills pills={domainTabs} />
|
|
|
|
</div>
|
|
|
|
</Responsive>
|
|
|
|
</div>
|
|
|
|
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.px15].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
{
|
|
|
|
!activeDomain &&
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.py15, _s.mt15, _s.mb15].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
<Heading size='h1'>
|
2020-08-18 21:43:06 +01:00
|
|
|
<a href={`https://trends.gab.com/trend?url=${headlineLink}`} className={[_s.noUnderline, _s.cPrimary].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
{headline}
|
|
|
|
</a>
|
|
|
|
</Heading>
|
|
|
|
</div>
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
2020-08-06 06:12:03 +01:00
|
|
|
{
|
|
|
|
!activeDomain && leadHeadlines.length > 0 &&
|
2020-08-19 01:22:15 +01:00
|
|
|
<div className={[_s.d, _s.mb15].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.px15, _s.py10, _s.borderBottom1PX, _s.bgSubtle, _s.borderColorSecondary, _s.jcCenter].join(' ')}>
|
|
|
|
<Heading size='h2'>
|
|
|
|
<Icon id='trends' className={[_s.mr10].join(' ')} size='18px' />
|
|
|
|
Headlines
|
2020-08-06 06:12:03 +01:00
|
|
|
</Heading>
|
|
|
|
</div>
|
2020-08-19 01:22:15 +01:00
|
|
|
{
|
|
|
|
leadHeadlines.map((lead) => (
|
|
|
|
<Button
|
|
|
|
isText
|
|
|
|
backgroundColor='none'
|
|
|
|
color='primary'
|
|
|
|
className={[_s.d, _s.py7].join(' ')}
|
|
|
|
href={`https://trends.gab.com/trend?url=${lead.href}`}
|
|
|
|
>
|
|
|
|
<Text>
|
|
|
|
{lead.title}
|
|
|
|
</Text>
|
|
|
|
</Button>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
2020-08-06 06:12:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
<div>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.px15, _s.mt15, _s.py10, _s.borderBottom1PX, _s.bgSubtle, _s.borderColorSecondary, _s.jcCenter].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
<Heading size='h2'>
|
|
|
|
<Icon id='trends' className={[_s.mr10].join(' ')} size='18px' />
|
|
|
|
{todaysTopTitle}
|
|
|
|
</Heading>
|
|
|
|
</div>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={[_s.d, _s.py10].join(' ')}>
|
2020-08-06 06:12:03 +01:00
|
|
|
{
|
|
|
|
todaysTop.map((block, i) => (
|
|
|
|
<TrendsItem
|
|
|
|
key={`explore-trending-item-${i}`}
|
|
|
|
index={i + 1}
|
|
|
|
title={block.pagePreview.title}
|
|
|
|
author={block.domain.domain}
|
|
|
|
description={block.pagePreview.description}
|
|
|
|
url={`https://trends.gab.com/trend?url=${block.pagePreview.url}`}
|
|
|
|
date={block.created}
|
|
|
|
isLast={todaysTop.length - 1 === i}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</Block>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
isError: state.getIn(['gab_trends', 'partner', 'isError']),
|
|
|
|
isLoading: state.getIn(['gab_trends', 'partner', 'isLoading']),
|
|
|
|
items: state.getIn(['gab_trends', 'partner', 'items']),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onfetchGabTrends: () => dispatch(fetchGabTrends('partner')),
|
|
|
|
})
|
|
|
|
|
|
|
|
News.propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isError: PropTypes.bool,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
items: PropTypes.object,
|
|
|
|
onfetchGabTrends: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRouter(connect(mapStateToProps, mapDispatchToProps)(News))
|