|
| 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 | + |
| 11 | +const mapStateToProps = state => ({ |
| 12 | + locked: state.getIn(['accounts', me, 'locked']), |
| 13 | + count: state.getIn(['user_lists', 'follow_requests', 'items'], ImmutableList()).size, |
| 14 | +}); |
| 15 | + |
| 16 | +export default @withRouter |
| 17 | +@connect(mapStateToProps) |
| 18 | +class FollowRequestsNavLink extends React.Component { |
| 19 | + |
| 20 | + static propTypes = { |
| 21 | + dispatch: PropTypes.func.isRequired, |
| 22 | + locked: PropTypes.bool, |
| 23 | + count: PropTypes.number.isRequired, |
| 24 | + }; |
| 25 | + |
| 26 | + componentDidMount () { |
| 27 | + const { dispatch, locked } = this.props; |
| 28 | + |
| 29 | + if (locked) { |
| 30 | + dispatch(fetchFollowRequests()); |
| 31 | + } |
| 32 | + } |
| 33 | + |
| 34 | + render () { |
| 35 | + const { locked, count } = this.props; |
| 36 | + |
| 37 | + if (!locked || count === 0) { |
| 38 | + return null; |
| 39 | + } |
| 40 | + |
| 41 | + 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>; |
| 42 | + } |
| 43 | + |
| 44 | +} |
0 commit comments