suggestions.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. const mapStateToProps = state => ({
  9. suggestions: state.getIn(['suggestions', 'items']),
  10. isLoading: state.getIn(['suggestions', 'isLoading']),
  11. });
  12. export default @connect(mapStateToProps)
  13. class Suggestions extends React.PureComponent {
  14. static propTypes = {
  15. isLoading: PropTypes.bool,
  16. suggestions: ImmutablePropTypes.list,
  17. dispatch: PropTypes.func.isRequired,
  18. };
  19. componentDidMount () {
  20. const { dispatch } = this.props;
  21. dispatch(fetchSuggestions(true));
  22. }
  23. render () {
  24. const { isLoading, suggestions } = this.props;
  25. return (
  26. <div className='explore__suggestions'>
  27. {isLoading ? <LoadingIndicator /> : suggestions.map(suggestion => (
  28. <AccountCard key={suggestion.get('account')} id={suggestion.get('account')} />
  29. ))}
  30. </div>
  31. );
  32. }
  33. }