bigbuffet-rw/app/soapbox/features/ui/components/compose_modal.js

71 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { connect } from 'react-redux';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component';
import ComposeFormContainer from '../../compose/containers/compose_form_container';
2020-05-28 15:52:07 -07:00
import IconButton from 'soapbox/components/icon_button';
2020-03-27 13:59:38 -07:00
import { openModal } from '../../../actions/modal';
import { cancelReplyCompose } from '../../../actions/compose';
const messages = defineMessages({
close: { id: 'lightbox.close', defaultMessage: 'Close' },
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
});
const mapStateToProps = state => {
const me = state.get('me');
2020-03-27 13:59:38 -07:00
return {
account: state.getIn(['accounts', me]),
composeText: state.getIn(['compose', 'text']),
};
};
class ComposeModal extends ImmutablePureComponent {
static propTypes = {
account: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
composeText: PropTypes.string,
dispatch: PropTypes.func.isRequired,
};
onClickClose = () => {
2020-04-14 11:44:40 -07:00
const { composeText, dispatch, onClose, intl } = this.props;
2020-03-27 13:59:38 -07:00
if (composeText) {
dispatch(openModal('CONFIRM', {
message: <FormattedMessage id='confirmations.delete.message' defaultMessage='Are you sure you want to delete this post?' />,
confirm: intl.formatMessage(messages.confirm),
onConfirm: () => dispatch(cancelReplyCompose()),
onCancel: () => dispatch(openModal('COMPOSE')),
}));
2020-04-14 11:44:40 -07:00
} else {
2020-03-27 13:59:38 -07:00
onClose('COMPOSE');
}
};
render() {
2020-03-27 13:59:38 -07:00
const { intl } = this.props;
return (
<div className='modal-root__modal compose-modal'>
<div className='compose-modal__header'>
<h3 className='compose-modal__header__title'>
<FormattedMessage id='navigation_bar.compose' defaultMessage='Compose new post' />
</h3>
<IconButton className='compose-modal__close' title={intl.formatMessage(messages.close)} icon='times' onClick={this.onClickClose} size={20} />
</div>
<div className='compose-modal__content compose-modal__content--scroll'>
2020-06-02 16:31:55 -07:00
<ComposeFormContainer />
2020-03-27 13:59:38 -07:00
</div>
</div>
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}
export default injectIntl(connect(mapStateToProps)(ComposeModal));