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.

50 lines
1.2 KiB

  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. muteAccount,
  10. unmuteAccount,
  11. } from '../actions/accounts';
  12. const makeMapStateToProps = () => {
  13. const getAccount = makeGetAccount();
  14. const mapStateToProps = (state, props) => ({
  15. account: getAccount(state, props.id),
  16. me: state.getIn(['meta', 'me'])
  17. });
  18. return mapStateToProps;
  19. };
  20. const mapDispatchToProps = (dispatch) => ({
  21. onFollow (account) {
  22. if (account.getIn(['relationship', 'following'])) {
  23. dispatch(unfollowAccount(account.get('id')));
  24. } else {
  25. dispatch(followAccount(account.get('id')));
  26. }
  27. },
  28. onBlock (account) {
  29. if (account.getIn(['relationship', 'blocking'])) {
  30. dispatch(unblockAccount(account.get('id')));
  31. } else {
  32. dispatch(blockAccount(account.get('id')));
  33. }
  34. },
  35. onMute (account) {
  36. if (account.getIn(['relationship', 'muting'])) {
  37. dispatch(unmuteAccount(account.get('id')));
  38. } else {
  39. dispatch(muteAccount(account.get('id')));
  40. }
  41. }
  42. });
  43. export default connect(makeMapStateToProps, mapDispatchToProps)(Account);