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.

33 lines
1.2 KiB

  1. import { openDropdownMenu, closeDropdownMenu } from 'flavours/glitch/actions/dropdown_menu';
  2. import { openModal, closeModal } from 'flavours/glitch/actions/modal';
  3. import { connect } from 'react-redux';
  4. import DropdownMenu from 'flavours/glitch/components/dropdown_menu';
  5. import { isUserTouching } from 'flavours/glitch/util/is_mobile';
  6. const mapStateToProps = state => ({
  7. isModalOpen: state.get('modal').modalType === 'ACTIONS',
  8. dropdownPlacement: state.getIn(['dropdown_menu', 'placement']),
  9. openDropdownId: state.getIn(['dropdown_menu', 'openId']),
  10. openedViaKeyboard: state.getIn(['dropdown_menu', 'keyboard']),
  11. });
  12. const mapDispatchToProps = (dispatch, { status, items }) => ({
  13. onOpen(id, onItemClick, dropdownPlacement, keyboard) {
  14. dispatch(isUserTouching() ? openModal('ACTIONS', {
  15. status,
  16. actions: items.map(
  17. (item, i) => item ? {
  18. ...item,
  19. name: `${item.text}-${i}`,
  20. onClick: item.action ? ((e) => { return onItemClick(i, e) }) : null,
  21. } : null
  22. ),
  23. }) : openDropdownMenu(id, dropdownPlacement, keyboard));
  24. },
  25. onClose(id) {
  26. dispatch(closeModal());
  27. dispatch(closeDropdownMenu(id));
  28. },
  29. });
  30. export default connect(mapStateToProps, mapDispatchToProps)(DropdownMenu);