2020-03-11 19:56:18 -04:00
|
|
|
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import { openModal } from '../../actions/modal'
|
|
|
|
import { cancelReplyCompose } from '../../actions/compose'
|
|
|
|
import ModalLayout from './modal_layout'
|
|
|
|
import TimelineComposeBlock from '../timeline_compose_block'
|
2019-07-02 03:10:25 -04:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2019-07-22 23:10:05 -04:00
|
|
|
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
|
2019-08-07 01:02:36 -04:00
|
|
|
title: { id: 'navigation_bar.compose', defaultMessage: 'Compose new gab' },
|
2020-03-11 19:56:18 -04:00
|
|
|
})
|
2019-07-02 03:10:25 -04:00
|
|
|
|
|
|
|
const mapStateToProps = state => {
|
|
|
|
return {
|
2019-07-22 23:10:05 -04:00
|
|
|
composeText: state.getIn(['compose', 'text']),
|
2019-07-02 03:10:25 -04:00
|
|
|
};
|
2020-03-11 19:56:18 -04:00
|
|
|
}
|
2019-07-02 03:10:25 -04:00
|
|
|
|
2020-02-25 11:04:44 -05:00
|
|
|
export default
|
|
|
|
@connect(mapStateToProps)
|
2019-08-07 01:02:36 -04:00
|
|
|
@injectIntl
|
2019-07-02 03:10:25 -04:00
|
|
|
class ComposeModal extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
2019-07-22 23:10:05 -04:00
|
|
|
composeText: PropTypes.string,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
2019-07-02 03:10:25 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
onClickClose = () => {
|
2020-03-06 23:53:28 -05:00
|
|
|
const { composeText, dispatch, onClose, intl } = this.props;
|
2019-07-22 23:10:05 -04:00
|
|
|
|
|
|
|
if (composeText) {
|
|
|
|
dispatch(openModal('CONFIRM', {
|
2020-03-11 19:56:18 -04:00
|
|
|
title: <FormattedMessage id='discard-gab-title' defaultMessage='Discard gab?' />,
|
|
|
|
message: <FormattedMessage id='discard-gab-message' defaultMessage="This can't be undone and you'll lose your draft." />,
|
2019-07-22 23:10:05 -04:00
|
|
|
confirm: intl.formatMessage(messages.confirm),
|
|
|
|
onConfirm: () => dispatch(cancelReplyCompose()),
|
|
|
|
onCancel: () => dispatch(openModal('COMPOSE')),
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
onClose('COMPOSE');
|
|
|
|
}
|
2019-07-02 03:10:25 -04:00
|
|
|
};
|
|
|
|
|
2020-03-06 23:53:28 -05:00
|
|
|
render() {
|
2020-03-11 19:56:18 -04:00
|
|
|
const { intl } = this.props
|
2019-07-02 03:10:25 -04:00
|
|
|
|
|
|
|
return (
|
2020-03-06 23:53:28 -05:00
|
|
|
<ModalLayout
|
|
|
|
noPadding
|
2020-03-12 12:09:15 -04:00
|
|
|
title={intl.formatMessage(messages.title)}
|
|
|
|
onClose={this.onClickClose}
|
2020-03-06 23:53:28 -05:00
|
|
|
>
|
|
|
|
<TimelineComposeBlock modal />
|
2019-08-07 01:02:36 -04:00
|
|
|
</ModalLayout>
|
2019-07-02 03:10:25 -04:00
|
|
|
);
|
|
|
|
}
|
2020-01-28 11:29:37 -05:00
|
|
|
}
|