about summary refs log tree commit diff
path: root/app/assets/javascripts/components/features/favourited_statuses/index.jsx
blob: a2d5217365bca5b300015ade91ba9bad9e4533b1 (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
import { connect } from 'react-redux';
import PureRenderMixin from 'react-addons-pure-render-mixin';
import ImmutablePropTypes from 'react-immutable-proptypes';
import LoadingIndicator from '../../components/loading_indicator';
import { fetchFavouritedStatuses, expandFavouritedStatuses } from '../../actions/favourites';
import Column from '../ui/components/column';
import StatusList from '../../components/status_list';
import ColumnBackButton from '../public_timeline/components/column_back_button';
import { defineMessages, injectIntl } from 'react-intl';

const messages = defineMessages({
  heading: { id: 'column.favourites', defaultMessage: 'Favourites' }
});

const mapStateToProps = state => ({
  statusIds: state.getIn(['status_lists', 'favourites', 'items']),
  loaded: state.getIn(['status_lists', 'favourites', 'loaded']),
  me: state.getIn(['meta', 'me'])
});

const Favourites = React.createClass({

  propTypes: {
    params: React.PropTypes.object.isRequired,
    dispatch: React.PropTypes.func.isRequired,
    statusIds: ImmutablePropTypes.list.isRequired,
    loaded: React.PropTypes.bool,
    intl: React.PropTypes.object.isRequired,
    me: React.PropTypes.number.isRequired
  },

  mixins: [PureRenderMixin],

  componentWillMount () {
    this.props.dispatch(fetchFavouritedStatuses());
  },

  handleScrollToBottom () {
    this.props.dispatch(expandFavouritedStatuses());
  },

  render () {
    const { statusIds, loaded, intl, me } = this.props;

    if (!loaded) {
      return (
        <Column>
          <LoadingIndicator />
        </Column>
      );
    }

    return (
      <Column icon='star' heading={intl.formatMessage(messages.heading)}>
        <ColumnBackButton />
        <StatusList statusIds={statusIds} me={me} onScrollToBottom={this.handleScrollToBottom} />
      </Column>
    );
  }

});

export default connect(mapStateToProps)(injectIntl(Favourites));