The code powering m.abunchtell.com https://m.abunchtell.com
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.0 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. const messages = defineMessages({
  10. remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' },
  11. add: { id: 'lists.account.add', defaultMessage: 'Add to list' },
  12. });
  13. const MapStateToProps = (state, { listId, added }) => ({
  14. list: state.get('lists').get(listId),
  15. added: typeof added === 'undefined' ? state.getIn(['listAdder', 'lists', 'items']).includes(listId) : added,
  16. });
  17. const mapDispatchToProps = (dispatch, { listId }) => ({
  18. onRemove: () => dispatch(removeFromListAdder(listId)),
  19. onAdd: () => dispatch(addToListAdder(listId)),
  20. });
  21. export default @connect(MapStateToProps, mapDispatchToProps)
  22. @injectIntl
  23. class List extends ImmutablePureComponent {
  24. static propTypes = {
  25. list: ImmutablePropTypes.map.isRequired,
  26. intl: PropTypes.object.isRequired,
  27. onRemove: PropTypes.func.isRequired,
  28. onAdd: PropTypes.func.isRequired,
  29. added: PropTypes.bool,
  30. };
  31. static defaultProps = {
  32. added: false,
  33. };
  34. render () {
  35. const { list, intl, onRemove, onAdd, added } = this.props;
  36. let button;
  37. if (added) {
  38. button = <IconButton icon='times' title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
  39. } else {
  40. button = <IconButton icon='plus' title={intl.formatMessage(messages.add)} onClick={onAdd} />;
  41. }
  42. return (
  43. <div className='list'>
  44. <div className='list__wrapper'>
  45. <div className='list__display-name'>
  46. <i className='fa fa-fw fa-list-ul column-link__icon' />
  47. {list.get('title')}
  48. </div>
  49. <div className='account__relationship'>
  50. {button}
  51. </div>
  52. </div>
  53. </div>
  54. );
  55. }
  56. }