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.

40 lines
1007 B

  1. import { connect } from 'react-redux';
  2. import { makeGetAccount } from '../selectors';
  3. import Account from '../components/account';
  4. import {
  5. followAccount,
  6. unfollowAccount,
  7. blockAccount,
  8. unblockAccount
  9. } from '../actions/accounts';
  10. const makeMapStateToProps = () => {
  11. const getAccount = makeGetAccount();
  12. const mapStateToProps = (state, props) => ({
  13. account: getAccount(state, props.id),
  14. me: state.getIn(['meta', 'me'])
  15. });
  16. return mapStateToProps;
  17. };
  18. const mapDispatchToProps = (dispatch) => ({
  19. onFollow (account) {
  20. if (account.getIn(['relationship', 'following'])) {
  21. dispatch(unfollowAccount(account.get('id')));
  22. } else {
  23. dispatch(followAccount(account.get('id')));
  24. }
  25. },
  26. onBlock (account) {
  27. if (account.getIn(['relationship', 'blocking'])) {
  28. dispatch(unblockAccount(account.get('id')));
  29. } else {
  30. dispatch(blockAccount(account.get('id')));
  31. }
  32. }
  33. });
  34. export default connect(makeMapStateToProps, mapDispatchToProps)(Account);