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' // const messages = defineMessages({ // title: { id: 'trends.title', defaultMessage: 'Trending right now' }, // }) 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')), }) export default @withRouter @connect(mapStateToProps, mapDispatchToProps) class Explore extends PureComponent { static contextTypes = { router: PropTypes.object.isRequired, } static propTypes = { intl: PropTypes.object.isRequired, isError: PropTypes.bool, isLoading: PropTypes.bool, items: PropTypes.object, onfetchGabTrends: PropTypes.func.isRequired, } state = { activeDomain: null, } updateOnProps = [ 'items', 'isLoading', 'isError', ] 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 }) } } render () { const { intl, isError, isLoading, items, } = this.props const { activeDomain } = this.state if (isError || !isObject(items)) { return