The code powering m.abunchtell.com https://m.abunchtell.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

80 rindas
2.7 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 { setupListEditor, clearListSuggestions, resetListEditor } from '../../actions/lists';
  8. import Account from './components/account';
  9. import Search from './components/search';
  10. import EditListForm from './components/edit_list_form';
  11. import Motion from '../ui/util/optional_motion';
  12. import spring from 'react-motion/lib/spring';
  13. const mapStateToProps = state => ({
  14. accountIds: state.getIn(['listEditor', 'accounts', 'items']),
  15. searchAccountIds: state.getIn(['listEditor', 'suggestions', 'items']),
  16. });
  17. const mapDispatchToProps = dispatch => ({
  18. onInitialize: listId => dispatch(setupListEditor(listId)),
  19. onClear: () => dispatch(clearListSuggestions()),
  20. onReset: () => dispatch(resetListEditor()),
  21. });
  22. export default @connect(mapStateToProps, mapDispatchToProps)
  23. @injectIntl
  24. class ListEditor extends ImmutablePureComponent {
  25. static propTypes = {
  26. listId: PropTypes.string.isRequired,
  27. onClose: PropTypes.func.isRequired,
  28. intl: PropTypes.object.isRequired,
  29. onInitialize: PropTypes.func.isRequired,
  30. onClear: PropTypes.func.isRequired,
  31. onReset: PropTypes.func.isRequired,
  32. accountIds: ImmutablePropTypes.list.isRequired,
  33. searchAccountIds: ImmutablePropTypes.list.isRequired,
  34. };
  35. componentDidMount () {
  36. const { onInitialize, listId } = this.props;
  37. onInitialize(listId);
  38. }
  39. componentWillUnmount () {
  40. const { onReset } = this.props;
  41. onReset();
  42. }
  43. render () {
  44. const { accountIds, searchAccountIds, onClear } = this.props;
  45. const showSearch = searchAccountIds.size > 0;
  46. return (
  47. <div className='modal-root__modal list-editor'>
  48. <EditListForm />
  49. <Search />
  50. <div className='drawer__pager'>
  51. <div className='drawer__inner list-editor__accounts'>
  52. {accountIds.map(accountId => <Account key={accountId} accountId={accountId} added />)}
  53. </div>
  54. {showSearch && <div role='button' tabIndex='-1' className='drawer__backdrop' onClick={onClear} />}
  55. <Motion defaultStyle={{ x: -100 }} style={{ x: spring(showSearch ? 0 : -100, { stiffness: 210, damping: 20 }) }}>
  56. {({ x }) => (
  57. <div className='drawer__inner backdrop' style={{ transform: x === 0 ? null : `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}>
  58. {searchAccountIds.map(accountId => <Account key={accountId} accountId={accountId} />)}
  59. </div>
  60. )}
  61. </Motion>
  62. </div>
  63. </div>
  64. );
  65. }
  66. }