import { connect } from 'react-redux'; import { openDropdownMenu, closeDropdownMenu } from '../actions/dropdown-menu'; import { openModal, closeModal } from '../actions/modals'; import DropdownMenu from '../components/dropdown-menu'; import { isUserTouching } from '../is-mobile'; import type { Dispatch } from 'redux'; import type { DropdownPlacement, IDropdown } from 'soapbox/components/dropdown-menu'; import type { RootState } from 'soapbox/store'; const mapStateToProps = (state: RootState) => ({ isModalOpen: Boolean(state.modals.size && state.modals.last()!.modalType === 'ACTIONS'), dropdownPlacement: state.dropdown_menu.placement, openDropdownId: state.dropdown_menu.openId, openedViaKeyboard: state.dropdown_menu.keyboard, }); const mapDispatchToProps = (dispatch: Dispatch, { status, items, ...filteredProps }: Partial) => ({ onOpen( id: number, onItemClick: React.EventHandler, dropdownPlacement: DropdownPlacement, keyboard: boolean, ) { dispatch(isUserTouching() ? openModal('ACTIONS', { status, actions: items, onClick: onItemClick, }) : openDropdownMenu(id, dropdownPlacement, keyboard)); if (filteredProps.onOpen) { filteredProps.onOpen(id, onItemClick, dropdownPlacement, keyboard); } }, onClose(id: number) { dispatch(closeModal('ACTIONS')); dispatch(closeDropdownMenu(id)); if (filteredProps.onClose) { filteredProps.onClose(id); } }, }); export default connect(mapStateToProps, mapDispatchToProps)(DropdownMenu);