You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
2.0 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import { connect } from 'react-redux';
  6. import { injectIntl, defineMessages } from 'react-intl';
  7. import Column from '../ui/components/column';
  8. import ColumnHeader from '../../components/column_header';
  9. import Hashtag from '../../components/hashtag';
  10. import classNames from 'classnames';
  11. import { fetchTrends } from '../../actions/trends';
  12. const messages = defineMessages({
  13. title: { id: 'trends.header', defaultMessage: 'Trending now' },
  14. refreshTrends: { id: 'trends.refresh', defaultMessage: 'Refresh trends' },
  15. });
  16. const mapStateToProps = state => ({
  17. trends: state.getIn(['trends', 'items']),
  18. loading: state.getIn(['trends', 'isLoading']),
  19. });
  20. const mapDispatchToProps = dispatch => ({
  21. fetchTrends: () => dispatch(fetchTrends()),
  22. });
  23. @connect(mapStateToProps, mapDispatchToProps)
  24. @injectIntl
  25. export default class Trends extends ImmutablePureComponent {
  26. static propTypes = {
  27. intl: PropTypes.object.isRequired,
  28. trends: ImmutablePropTypes.list,
  29. fetchTrends: PropTypes.func.isRequired,
  30. loading: PropTypes.bool,
  31. };
  32. componentDidMount () {
  33. this.props.fetchTrends();
  34. }
  35. handleRefresh = () => {
  36. this.props.fetchTrends();
  37. }
  38. render () {
  39. const { trends, loading, intl } = this.props;
  40. return (
  41. <Column>
  42. <ColumnHeader
  43. icon='fire'
  44. title={intl.formatMessage(messages.title)}
  45. extraButton={(
  46. <button className='column-header__button' title={intl.formatMessage(messages.refreshTrends)} aria-label={intl.formatMessage(messages.refreshTrends)} onClick={this.handleRefresh}><i className={classNames('fa', 'fa-refresh', { 'fa-spin': loading })} /></button>
  47. )}
  48. />
  49. <div className='scrollable'>
  50. {trends && trends.map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
  51. </div>
  52. </Column>
  53. );
  54. }
  55. }