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.

44 lines
1.4 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { fetchFollowRequests } from 'mastodon/actions/accounts';
  4. import { connect } from 'react-redux';
  5. import { NavLink, withRouter } from 'react-router-dom';
  6. import IconWithBadge from 'mastodon/components/icon_with_badge';
  7. import { me } from 'mastodon/initial_state';
  8. import { List as ImmutableList } from 'immutable';
  9. import { FormattedMessage } from 'react-intl';
  10. const mapStateToProps = state => ({
  11. locked: state.getIn(['accounts', me, 'locked']),
  12. count: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size,
  13. });
  14. export default @withRouter
  15. @connect(mapStateToProps)
  16. class FollowRequestsNavLink extends React.Component {
  17. static propTypes = {
  18. dispatch: PropTypes.func.isRequired,
  19. locked: PropTypes.bool,
  20. count: PropTypes.number.isRequired,
  21. };
  22. componentDidMount () {
  23. const { dispatch, locked } = this.props;
  24. if (locked) {
  25. dispatch(fetchFollowRequests());
  26. }
  27. }
  28. render () {
  29. const { locked, count } = this.props;
  30. if (!locked || count === 0) {
  31. return null;
  32. }
  33. return <NavLink className='column-link column-link--transparent' to='/follow_requests'><IconWithBadge className='column-link__icon' id='user-plus' count={count} /><FormattedMessage id='navigation_bar.follow_requests' defaultMessage='Follow requests' /></NavLink>;
  34. }
  35. }