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.

69 lines
2.1 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { connect } from 'react-redux';
  4. import ImmutablePureComponent from 'react-immutable-pure-component';
  5. import ImmutablePropTypes from 'react-immutable-proptypes';
  6. import IconButton from '../../../components/icon_button';
  7. import { defineMessages, injectIntl } from 'react-intl';
  8. import { removeFromListAdder, addToListAdder } from '../../../actions/lists';
  9. import Icon from 'mastodon/components/icon';
  10. const messages = defineMessages({
  11. remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' },
  12. add: { id: 'lists.account.add', defaultMessage: 'Add to list' },
  13. });
  14. const MapStateToProps = (state, { listId, added }) => ({
  15. list: state.get('lists').get(listId),
  16. added: typeof added === 'undefined' ? state.getIn(['listAdder', 'lists', 'items']).includes(listId) : added,
  17. });
  18. const mapDispatchToProps = (dispatch, { listId }) => ({
  19. onRemove: () => dispatch(removeFromListAdder(listId)),
  20. onAdd: () => dispatch(addToListAdder(listId)),
  21. });
  22. class List extends ImmutablePureComponent {
  23. static propTypes = {
  24. list: ImmutablePropTypes.map.isRequired,
  25. intl: PropTypes.object.isRequired,
  26. onRemove: PropTypes.func.isRequired,
  27. onAdd: PropTypes.func.isRequired,
  28. added: PropTypes.bool,
  29. };
  30. static defaultProps = {
  31. added: false,
  32. };
  33. render () {
  34. const { list, intl, onRemove, onAdd, added } = this.props;
  35. let button;
  36. if (added) {
  37. button = <IconButton icon='times' title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
  38. } else {
  39. button = <IconButton icon='plus' title={intl.formatMessage(messages.add)} onClick={onAdd} />;
  40. }
  41. return (
  42. <div className='list'>
  43. <div className='list__wrapper'>
  44. <div className='list__display-name'>
  45. <Icon id='list-ul' className='column-link__icon' fixedWidth />
  46. {list.get('title')}
  47. </div>
  48. <div className='account__relationship'>
  49. {button}
  50. </div>
  51. </div>
  52. </div>
  53. );
  54. }
  55. }
  56. export default connect(MapStateToProps, mapDispatchToProps)(injectIntl(List));