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.

73 lines
2.0 KiB

  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import ImmutablePropTypes from 'react-immutable-proptypes';
  4. import { connect } from 'react-redux';
  5. import ImmutablePureComponent from 'react-immutable-pure-component';
  6. import { injectIntl } from 'react-intl';
  7. import { setupListAdder, resetListAdder } from '../../actions/lists';
  8. import { createSelector } from 'reselect';
  9. import List from './components/list';
  10. import Account from './components/account';
  11. import NewListForm from '../lists/components/new_list_form';
  12. // hack
  13. const getOrderedLists = createSelector([state => state.get('lists')], lists => {
  14. if (!lists) {
  15. return lists;
  16. }
  17. return lists.toList().filter(item => !!item).sort((a, b) => a.get('title').localeCompare(b.get('title')));
  18. });
  19. const mapStateToProps = state => ({
  20. listIds: getOrderedLists(state).map(list=>list.get('id')),
  21. });
  22. const mapDispatchToProps = dispatch => ({
  23. onInitialize: accountId => dispatch(setupListAdder(accountId)),
  24. onReset: () => dispatch(resetListAdder()),
  25. });
  26. export default @connect(mapStateToProps, mapDispatchToProps)
  27. @injectIntl
  28. class ListAdder extends ImmutablePureComponent {
  29. static propTypes = {
  30. accountId: PropTypes.string.isRequired,
  31. onClose: PropTypes.func.isRequired,
  32. intl: PropTypes.object.isRequired,
  33. onInitialize: PropTypes.func.isRequired,
  34. onReset: PropTypes.func.isRequired,
  35. listIds: ImmutablePropTypes.list.isRequired,
  36. };
  37. componentDidMount () {
  38. const { onInitialize, accountId } = this.props;
  39. onInitialize(accountId);
  40. }
  41. componentWillUnmount () {
  42. const { onReset } = this.props;
  43. onReset();
  44. }
  45. render () {
  46. const { accountId, listIds } = this.props;
  47. return (
  48. <div className='modal-root__modal list-adder'>
  49. <div className='list-adder__account'>
  50. <Account accountId={accountId} />
  51. </div>
  52. <NewListForm />
  53. <div className='list-adder__lists'>
  54. {listIds.map(ListId => <List key={ListId} listId={ListId} />)}
  55. </div>
  56. </div>
  57. );
  58. }
  59. }