suggestions.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import AccountCard from 'mastodon/features/directory/components/account_card';
  5. import LoadingIndicator from 'mastodon/components/loading_indicator';
  6. import { connect } from 'react-redux';
  7. import { fetchSuggestions } from 'mastodon/actions/suggestions';
  8. import { FormattedMessage } from 'react-intl';
  9. const mapStateToProps = state => ({
  10. suggestions: state.getIn(['suggestions', 'items']),
  11. isLoading: state.getIn(['suggestions', 'isLoading']),
  12. });
  13. export default @connect(mapStateToProps)
  14. class Suggestions extends React.PureComponent {
  15. static propTypes = {
  16. isLoading: PropTypes.bool,
  17. suggestions: ImmutablePropTypes.list,
  18. dispatch: PropTypes.func.isRequired,
  19. };
  20. componentDidMount () {
  21. const { dispatch } = this.props;
  22. dispatch(fetchSuggestions(true));
  23. }
  24. render () {
  25. const { isLoading, suggestions } = this.props;
  26. if (!isLoading && suggestions.isEmpty()) {
  27. return (
  28. <div className='explore__suggestions scrollable scrollable--flex'>
  29. <div className='empty-column-indicator'>
  30. <FormattedMessage id='empty_column.explore_statuses' defaultMessage='Nothing is trending right now. Check back later!' />
  31. </div>
  32. </div>
  33. );
  34. }
  35. return (
  36. <div className='explore__suggestions'>
  37. {isLoading ? <LoadingIndicator /> : suggestions.map(suggestion => (
  38. <AccountCard key={suggestion.get('account')} id={suggestion.get('account')} />
  39. ))}
  40. </div>
  41. );
  42. }
  43. }