statuses.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import StatusList from 'mastodon/components/status_list';
  5. import { FormattedMessage } from 'react-intl';
  6. import { connect } from 'react-redux';
  7. import { fetchTrendingStatuses, expandTrendingStatuses } from 'mastodon/actions/trends';
  8. import { debounce } from 'lodash';
  9. import DismissableBanner from 'mastodon/components/dismissable_banner';
  10. const mapStateToProps = state => ({
  11. statusIds: state.getIn(['status_lists', 'trending', 'items']),
  12. isLoading: state.getIn(['status_lists', 'trending', 'isLoading'], true),
  13. hasMore: !!state.getIn(['status_lists', 'trending', 'next']),
  14. });
  15. export default @connect(mapStateToProps)
  16. class Statuses extends React.PureComponent {
  17. static propTypes = {
  18. statusIds: ImmutablePropTypes.list,
  19. isLoading: PropTypes.bool,
  20. hasMore: PropTypes.bool,
  21. multiColumn: PropTypes.bool,
  22. dispatch: PropTypes.func.isRequired,
  23. };
  24. componentDidMount () {
  25. const { dispatch } = this.props;
  26. dispatch(fetchTrendingStatuses());
  27. }
  28. handleLoadMore = debounce(() => {
  29. const { dispatch } = this.props;
  30. dispatch(expandTrendingStatuses());
  31. }, 300, { leading: true })
  32. render () {
  33. const { isLoading, hasMore, statusIds, multiColumn } = this.props;
  34. const emptyMessage = <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />;
  35. return (
  36. <>
  37. <DismissableBanner id='explore/statuses'>
  38. <FormattedMessage id='dismissable_banner.explore_statuses' defaultMessage='These posts from this and other servers in the decentralized network are gaining traction on this server right now.' />
  39. </DismissableBanner>
  40. <StatusList
  41. trackScroll
  42. statusIds={statusIds}
  43. scrollKey='explore-statuses'
  44. hasMore={hasMore}
  45. isLoading={isLoading}
  46. onLoadMore={this.handleLoadMore}
  47. emptyMessage={emptyMessage}
  48. bindToDocument={!multiColumn}
  49. withCounters
  50. />
  51. </>
  52. );
  53. }
  54. }