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. export default @connect(MapStateToProps, mapDispatchToProps)
  23. @injectIntl
  24. class List extends ImmutablePureComponent {
  25. static propTypes = {
  26. list: ImmutablePropTypes.map.isRequired,
  27. intl: PropTypes.object.isRequired,
  28. onRemove: PropTypes.func.isRequired,
  29. onAdd: PropTypes.func.isRequired,
  30. added: PropTypes.bool,
  31. };
  32. static defaultProps = {
  33. added: false,
  34. };
  35. render () {
  36. const { list, intl, onRemove, onAdd, added } = this.props;
  37. let button;
  38. if (added) {
  39. button = <IconButton icon='times' title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
  40. } else {
  41. button = <IconButton icon='plus' title={intl.formatMessage(messages.add)} onClick={onAdd} />;
  42. }
  43. return (
  44. <div className='list'>
  45. <div className='list__wrapper'>
  46. <div className='list__display-name'>
  47. <Icon id='list-ul' className='column-link__icon' fixedWidth />
  48. {list.get('title')}
  49. </div>
  50. <div className='account__relationship'>
  51. {button}
  52. </div>
  53. </div>
  54. </div>
  55. );
  56. }
  57. }