bigbuffet-rw/app/soapbox/features/ui/containers/modal-container.ts

45 lines
1.1 KiB
TypeScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import { connect } from 'react-redux';
import { cancelReplyCompose } from 'soapbox/actions/compose';
import { cancelEventCompose } from 'soapbox/actions/events';
import { closeModal } from 'soapbox/actions/modals';
import { cancelReport } from 'soapbox/actions/reports';
2022-11-16 05:32:32 -08:00
import ModalRoot, { ModalType } from '../components/modal-root';
2020-03-27 13:59:38 -07:00
import type { AppDispatch, RootState } from 'soapbox/store';
const mapStateToProps = (state: RootState) => {
const modal = state.modals.last({
modalType: null,
modalProps: {},
});
return {
type: modal.modalType as ModalType,
props: modal.modalProps,
};
};
2020-03-27 13:59:38 -07:00
const mapDispatchToProps = (dispatch: AppDispatch) => ({
onClose(type?: ModalType) {
switch (type) {
2022-05-12 12:32:32 -07:00
case 'COMPOSE':
dispatch(cancelReplyCompose());
break;
case 'COMPOSE_EVENT':
dispatch(cancelEventCompose());
break;
2022-05-12 12:32:32 -07:00
case 'REPORT':
dispatch(cancelReport());
break;
default:
break;
2020-03-27 13:59:38 -07:00
}
dispatch(closeModal(type));
2020-03-27 13:59:38 -07:00
},
});
export default connect(mapStateToProps, mapDispatchToProps)(ModalRoot);