79 lines
1.9 KiB
JavaScript
Raw Normal View History

2020-02-19 18:57:07 -05:00
import { injectIntl, defineMessages } from 'react-intl'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
2020-04-03 19:18:26 -04:00
import { fetchGabTrends } from '../../actions/gab_trends'
2020-02-19 18:57:07 -05:00
import PanelLayout from './panel_layout'
2020-04-28 01:33:58 -04:00
import ScrollableList from '../scrollable_list'
2020-04-29 18:32:49 -04:00
import TrendsItem from '../trends_item'
const messages = defineMessages({
2020-04-06 21:53:23 -04:00
title: { id: 'trends.title', defaultMessage: 'Trending right now' },
2020-02-19 18:57:07 -05:00
})
2020-04-11 18:29:19 -04:00
const mapStateToProps = (state) => ({
isError: state.getIn(['gab_trends', 'feed', 'isError']),
isLoading: state.getIn(['gab_trends', 'feed', 'isLoading']),
items: state.getIn(['gab_trends', 'feed', 'items']),
2020-04-03 19:18:26 -04:00
})
2020-04-11 18:29:19 -04:00
const mapDispatchToProps = (dispatch) => ({
onfetchGabTrends: () => dispatch(fetchGabTrends('feed')),
2020-04-11 18:29:19 -04:00
})
2020-02-19 18:57:07 -05:00
export default
@injectIntl
@connect(mapStateToProps, mapDispatchToProps)
class TrendsPanel extends ImmutablePureComponent {
static propTypes = {
intl: PropTypes.object.isRequired,
isError: PropTypes.bool,
isLoading: PropTypes.bool,
items: ImmutablePropTypes.list.isRequired,
onfetchGabTrends: PropTypes.func.isRequired,
2020-02-19 18:57:07 -05:00
}
2020-04-29 18:32:49 -04:00
updateOnProps = [
'items',
'isLoading',
'isError',
2020-04-29 18:32:49 -04:00
]
2020-04-28 01:33:58 -04:00
componentDidMount() {
this.props.onfetchGabTrends()
}
render() {
const {
intl,
isError,
isLoading,
items,
} = this.props
if (isError) return null
return (
2020-02-20 19:57:29 -05:00
<PanelLayout
noPadding
title={intl.formatMessage(messages.title)}
>
2020-04-29 18:32:49 -04:00
<ScrollableList
isLoading={isLoading}
2020-04-29 18:32:49 -04:00
scrollKey='trending-items'
>
2020-04-03 19:18:26 -04:00
{
items.slice(0, 8).map((trend, i) => (
2020-04-29 18:32:49 -04:00
<TrendsItem
key={`gab-trend-${i}`}
index={i + 1}
isLast={i === 7}
trend={trend}
/>
))
2020-04-03 19:18:26 -04:00
}
2020-04-29 18:32:49 -04:00
</ScrollableList>
</PanelLayout>
2020-02-19 18:57:07 -05:00
)
}
2020-02-19 18:57:07 -05:00
}