statuses.jsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import PropTypes from 'prop-types';
  2. import { PureComponent } from 'react';
  3. import { FormattedMessage } from 'react-intl';
  4. import { withRouter } from 'react-router-dom';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import { connect } from 'react-redux';
  7. import { debounce } from 'lodash';
  8. import { fetchTrendingStatuses, expandTrendingStatuses } from 'mastodon/actions/trends';
  9. import { DismissableBanner } from 'mastodon/components/dismissable_banner';
  10. import StatusList from 'mastodon/components/status_list';
  11. import { getStatusList } from 'mastodon/selectors';
  12. import { WithRouterPropTypes } from 'mastodon/utils/react_router';
  13. const mapStateToProps = state => ({
  14. statusIds: getStatusList(state, 'trending'),
  15. isLoading: state.getIn(['status_lists', 'trending', 'isLoading'], true),
  16. hasMore: !!state.getIn(['status_lists', 'trending', 'next']),
  17. });
  18. class Statuses extends PureComponent {
  19. static propTypes = {
  20. statusIds: ImmutablePropTypes.list,
  21. isLoading: PropTypes.bool,
  22. hasMore: PropTypes.bool,
  23. multiColumn: PropTypes.bool,
  24. dispatch: PropTypes.func.isRequired,
  25. ...WithRouterPropTypes,
  26. };
  27. componentDidMount () {
  28. const { dispatch, statusIds, history } = this.props;
  29. // If we're navigating back to the screen, do not trigger a reload
  30. if (history.action === 'POP' && statusIds.size > 0) {
  31. return;
  32. }
  33. dispatch(fetchTrendingStatuses());
  34. }
  35. handleLoadMore = debounce(() => {
  36. const { dispatch } = this.props;
  37. dispatch(expandTrendingStatuses());
  38. }, 300, { leading: true });
  39. render () {
  40. const { isLoading, hasMore, statusIds, multiColumn } = this.props;
  41. const emptyMessage = <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />;
  42. return (
  43. <StatusList
  44. trackScroll
  45. prepend={<DismissableBanner id='explore/statuses'><FormattedMessage id='dismissable_banner.explore_statuses' defaultMessage='These are posts from across the social web that are gaining traction today. Newer posts with more boosts and favorites are ranked higher.' /></DismissableBanner>}
  46. alwaysPrepend
  47. timelineId='explore'
  48. statusIds={statusIds}
  49. scrollKey='explore-statuses'
  50. hasMore={hasMore}
  51. isLoading={isLoading}
  52. onLoadMore={this.handleLoadMore}
  53. emptyMessage={emptyMessage}
  54. bindToDocument={!multiColumn}
  55. withCounters
  56. />
  57. );
  58. }
  59. }
  60. export default connect(mapStateToProps)(withRouter(Statuses));