闭社主体 forked from https://github.com/tootsuite/mastodon
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.

62 lines
1.9 KiB

  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import ImmutablePropTypes from 'react-immutable-proptypes';
  5. import LoadingIndicator from '../../components/loading_indicator';
  6. import { fetchFavouritedStatuses, expandFavouritedStatuses } from '../../actions/favourites';
  7. import Column from '../ui/components/column';
  8. import StatusList from '../../components/status_list';
  9. import ColumnBackButtonSlim from '../../components/column_back_button_slim';
  10. import { defineMessages, injectIntl } from 'react-intl';
  11. import ImmutablePureComponent from 'react-immutable-pure-component';
  12. const messages = defineMessages({
  13. heading: { id: 'column.favourites', defaultMessage: 'Favourites' },
  14. });
  15. const mapStateToProps = state => ({
  16. statusIds: state.getIn(['status_lists', 'favourites', 'items']),
  17. loaded: state.getIn(['status_lists', 'favourites', 'loaded']),
  18. me: state.getIn(['meta', 'me']),
  19. });
  20. class Favourites extends ImmutablePureComponent {
  21. static propTypes = {
  22. dispatch: PropTypes.func.isRequired,
  23. statusIds: ImmutablePropTypes.list.isRequired,
  24. loaded: PropTypes.bool,
  25. intl: PropTypes.object.isRequired,
  26. me: PropTypes.number.isRequired,
  27. };
  28. componentWillMount () {
  29. this.props.dispatch(fetchFavouritedStatuses());
  30. }
  31. handleScrollToBottom = () => {
  32. this.props.dispatch(expandFavouritedStatuses());
  33. }
  34. render () {
  35. const { statusIds, loaded, intl, me } = this.props;
  36. if (!loaded) {
  37. return (
  38. <Column>
  39. <LoadingIndicator />
  40. </Column>
  41. );
  42. }
  43. return (
  44. <Column icon='star' heading={intl.formatMessage(messages.heading)}>
  45. <ColumnBackButtonSlim />
  46. <StatusList {...this.props} scrollKey='favourited_statuses' onScrollToBottom={this.handleScrollToBottom} />
  47. </Column>
  48. );
  49. }
  50. }
  51. export default connect(mapStateToProps)(injectIntl(Favourites));