logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

index.js (2810B)


  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 Motion from '../ui/util/optional_motion';
  11. import spring from 'react-motion/lib/spring';
  12. const mapStateToProps = state => ({
  13. title: state.getIn(['listEditor', 'title']),
  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. @connect(mapStateToProps, mapDispatchToProps)
  23. @injectIntl
  24. export default 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. title: PropTypes.string.isRequired,
  33. accountIds: ImmutablePropTypes.list.isRequired,
  34. searchAccountIds: ImmutablePropTypes.list.isRequired,
  35. };
  36. componentDidMount () {
  37. const { onInitialize, listId } = this.props;
  38. onInitialize(listId);
  39. }
  40. componentWillUnmount () {
  41. const { onReset } = this.props;
  42. onReset();
  43. }
  44. render () {
  45. const { title, accountIds, searchAccountIds, onClear } = this.props;
  46. const showSearch = searchAccountIds.size > 0;
  47. return (
  48. <div className='modal-root__modal list-editor'>
  49. <h4>{title}</h4>
  50. <Search />
  51. <div className='drawer__pager'>
  52. <div className='drawer__inner list-editor__accounts'>
  53. {accountIds.map(accountId => <Account key={accountId} accountId={accountId} added />)}
  54. </div>
  55. {showSearch && <div role='button' tabIndex='-1' className='drawer__backdrop' onClick={onClear} />}
  56. <Motion defaultStyle={{ x: -100 }} style={{ x: spring(showSearch ? 0 : -100, { stiffness: 210, damping: 20 }) }}>
  57. {({ x }) => (
  58. <div className='drawer__inner backdrop' style={{ transform: x === 0 ? null : `translateX(${x}%)`, visibility: x === -100 ? 'hidden' : 'visible' }}>
  59. {searchAccountIds.map(accountId => <Account key={accountId} accountId={accountId} />)}
  60. </div>
  61. )}
  62. </Motion>
  63. </div>
  64. </div>
  65. );
  66. }
  67. }