about summary refs log tree commit diff
path: root/app/javascript/mastodon/features/trends/index.js
blob: f33af3e2e3fb45aeb8b61d0111ba84d2e2d82048 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { connect } from 'react-redux';
import { injectIntl, defineMessages } from 'react-intl';
import Column from '../ui/components/column';
import ColumnHeader from '../../components/column_header';
import Hashtag from '../../components/hashtag';
import classNames from 'classnames';
import { fetchTrends } from '../../actions/trends';

const messages = defineMessages({
  title: { id: 'trends.header', defaultMessage: 'Trending now' },
  refreshTrends: { id: 'trends.refresh', defaultMessage: 'Refresh trends' },
});

const mapStateToProps = state => ({
  trends: state.getIn(['trends', 'items']),
  loading: state.getIn(['trends', 'isLoading']),
});

const mapDispatchToProps = dispatch => ({
  fetchTrends: () => dispatch(fetchTrends()),
});

@connect(mapStateToProps, mapDispatchToProps)
@injectIntl
export default class Trends extends ImmutablePureComponent {

  static propTypes = {
    intl: PropTypes.object.isRequired,
    trends: ImmutablePropTypes.list,
    fetchTrends: PropTypes.func.isRequired,
    loading: PropTypes.bool,
  };

  componentDidMount () {
    this.props.fetchTrends();
  }

  handleRefresh = () => {
    this.props.fetchTrends();
  }

  render () {
    const { trends, loading, intl } = this.props;

    return (
      <Column>
        <ColumnHeader
          icon='fire'
          title={intl.formatMessage(messages.title)}
          extraButton={(
            <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>
          )}
        />

        <div className='scrollable'>
          {trends && trends.map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
        </div>
      </Column>
    );
  }

}