2020-03-27 13:59:38 -07:00
|
|
|
import { connect } from 'react-redux';
|
2022-01-10 14:25:06 -08:00
|
|
|
|
2022-05-30 11:23:55 -07:00
|
|
|
import { cancelReplyCompose } from 'soapbox/actions/compose';
|
2022-09-25 14:18:11 -07:00
|
|
|
import { cancelEventCompose } from 'soapbox/actions/events';
|
2022-05-30 11:23:55 -07:00
|
|
|
import { closeModal } from 'soapbox/actions/modals';
|
2022-05-11 06:25:48 -07:00
|
|
|
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
|
|
|
|
2022-11-12 06:18:24 -08:00
|
|
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
|
|
|
|
|
|
|
const mapStateToProps = (state: RootState) => {
|
|
|
|
const modal = state.modals.last({
|
2022-01-30 09:46:57 -08:00
|
|
|
modalType: null,
|
|
|
|
modalProps: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
2022-11-12 06:18:24 -08:00
|
|
|
type: modal.modalType as ModalType,
|
2022-01-30 09:46:57 -08:00
|
|
|
props: modal.modalProps,
|
|
|
|
};
|
|
|
|
};
|
2020-03-27 13:59:38 -07:00
|
|
|
|
2022-11-12 06:18:24 -08:00
|
|
|
const mapDispatchToProps = (dispatch: AppDispatch) => ({
|
|
|
|
onClose(type?: ModalType) {
|
2022-05-11 06:25:48 -07:00
|
|
|
switch (type) {
|
2022-05-12 12:32:32 -07:00
|
|
|
case 'COMPOSE':
|
|
|
|
dispatch(cancelReplyCompose());
|
|
|
|
break;
|
2022-09-25 14:18:11 -07:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2022-01-30 09:46:57 -08:00
|
|
|
dispatch(closeModal(type));
|
2020-03-27 13:59:38 -07:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ModalRoot);
|