suggestions.jsx 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 { fetchSuggestions } from 'mastodon/actions/suggestions';
  8. import { LoadingIndicator } from 'mastodon/components/loading_indicator';
  9. import AccountCard from 'mastodon/features/directory/components/account_card';
  10. import { WithRouterPropTypes } from 'mastodon/utils/react_router';
  11. const mapStateToProps = state => ({
  12. suggestions: state.getIn(['suggestions', 'items']),
  13. isLoading: state.getIn(['suggestions', 'isLoading']),
  14. });
  15. class Suggestions extends PureComponent {
  16. static propTypes = {
  17. isLoading: PropTypes.bool,
  18. suggestions: ImmutablePropTypes.list,
  19. dispatch: PropTypes.func.isRequired,
  20. ...WithRouterPropTypes,
  21. };
  22. componentDidMount () {
  23. const { dispatch, suggestions, history } = this.props;
  24. // If we're navigating back to the screen, do not trigger a reload
  25. if (history.action === 'POP' && suggestions.size > 0) {
  26. return;
  27. }
  28. dispatch(fetchSuggestions(true));
  29. }
  30. render () {
  31. const { isLoading, suggestions } = this.props;
  32. if (!isLoading && suggestions.isEmpty()) {
  33. return (
  34. <div className='explore__suggestions scrollable scrollable--flex'>
  35. <div className='empty-column-indicator'>
  36. <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />
  37. </div>
  38. </div>
  39. );
  40. }
  41. return (
  42. <div className='explore__suggestions scrollable' data-nosnippet>
  43. {isLoading ? <LoadingIndicator /> : suggestions.map(suggestion => (
  44. <AccountCard key={suggestion.get('account')} id={suggestion.get('account')} />
  45. ))}
  46. </div>
  47. );
  48. }
  49. }
  50. export default connect(mapStateToProps)(withRouter(Suggestions));