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.

65 lines
2.1 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import StatusList from 'flavours/glitch/components/status_list';
  5. import { FormattedMessage } from 'react-intl';
  6. import { connect } from 'react-redux';
  7. import { fetchTrendingStatuses, expandTrendingStatuses } from 'flavours/glitch/actions/trends';
  8. import { debounce } from 'lodash';
  9. import DismissableBanner from 'flavours/glitch/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. class Statuses extends React.PureComponent {
  16. static propTypes = {
  17. statusIds: ImmutablePropTypes.list,
  18. isLoading: PropTypes.bool,
  19. hasMore: PropTypes.bool,
  20. multiColumn: PropTypes.bool,
  21. dispatch: PropTypes.func.isRequired,
  22. };
  23. componentDidMount () {
  24. const { dispatch } = this.props;
  25. dispatch(fetchTrendingStatuses());
  26. }
  27. handleLoadMore = debounce(() => {
  28. const { dispatch } = this.props;
  29. dispatch(expandTrendingStatuses());
  30. }, 300, { leading: true });
  31. render () {
  32. const { isLoading, hasMore, statusIds, multiColumn } = this.props;
  33. const emptyMessage = <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />;
  34. return (
  35. <>
  36. <DismissableBanner id='explore/statuses'>
  37. <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.' />
  38. </DismissableBanner>
  39. <StatusList
  40. trackScroll
  41. statusIds={statusIds}
  42. scrollKey='explore-statuses'
  43. hasMore={hasMore}
  44. isLoading={isLoading}
  45. onLoadMore={this.handleLoadMore}
  46. emptyMessage={emptyMessage}
  47. bindToDocument={!multiColumn}
  48. withCounters
  49. />
  50. </>
  51. );
  52. }
  53. }
  54. export default connect(mapStateToProps)(Statuses);