logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

account.js (2458B)


  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import { makeGetAccount } from '../../../selectors';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import ImmutablePropTypes from 'react-immutable-proptypes';
  7. import Avatar from '../../../components/avatar';
  8. import DisplayName from '../../../components/display_name';
  9. import IconButton from '../../../components/icon_button';
  10. import { defineMessages, injectIntl } from 'react-intl';
  11. import { removeFromListEditor, addToListEditor } from '../../../actions/lists';
  12. const messages = defineMessages({
  13. remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' },
  14. add: { id: 'lists.account.add', defaultMessage: 'Add to list' },
  15. });
  16. const makeMapStateToProps = () => {
  17. const getAccount = makeGetAccount();
  18. const mapStateToProps = (state, { accountId, added }) => ({
  19. account: getAccount(state, accountId),
  20. added: typeof added === 'undefined' ? state.getIn(['listEditor', 'accounts', 'items']).includes(accountId) : added,
  21. });
  22. return mapStateToProps;
  23. };
  24. const mapDispatchToProps = (dispatch, { accountId }) => ({
  25. onRemove: () => dispatch(removeFromListEditor(accountId)),
  26. onAdd: () => dispatch(addToListEditor(accountId)),
  27. });
  28. @connect(makeMapStateToProps, mapDispatchToProps)
  29. @injectIntl
  30. export default class Account extends ImmutablePureComponent {
  31. static propTypes = {
  32. account: ImmutablePropTypes.map.isRequired,
  33. intl: PropTypes.object.isRequired,
  34. onRemove: PropTypes.func.isRequired,
  35. onAdd: PropTypes.func.isRequired,
  36. added: PropTypes.bool,
  37. };
  38. static defaultProps = {
  39. added: false,
  40. };
  41. render () {
  42. const { account, intl, onRemove, onAdd, added } = this.props;
  43. let button;
  44. if (added) {
  45. button = <IconButton icon='times' title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
  46. } else {
  47. button = <IconButton icon='plus' title={intl.formatMessage(messages.add)} onClick={onAdd} />;
  48. }
  49. return (
  50. <div className='account'>
  51. <div className='account__wrapper'>
  52. <div className='account__display-name'>
  53. <div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
  54. <DisplayName account={account} />
  55. </div>
  56. <div className='account__relationship'>
  57. {button}
  58. </div>
  59. </div>
  60. </div>
  61. );
  62. }
  63. }