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

89 lines
2.9 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import PropTypes from 'prop-types';
import React from 'react';
2020-03-27 13:59:38 -07:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
2022-03-21 11:09:01 -07:00
import { cancelReplyCompose } from '../../../actions/compose';
import { openModal, closeModal } from '../../../actions/modals';
import { Modal } from '../../../components/ui';
import ComposeFormContainer from '../../compose/containers/compose_form_container';
2020-03-27 13:59:38 -07:00
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']),
privacy: state.getIn(['compose', 'privacy']),
inReplyTo: state.getIn(['compose', 'in_reply_to']),
quote: state.getIn(['compose', 'quote']),
2020-03-27 13:59:38 -07:00
};
};
class ComposeModal extends ImmutablePureComponent {
static propTypes = {
account: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
onClose: PropTypes.func.isRequired,
composeText: PropTypes.string,
privacy: PropTypes.string,
inReplyTo: PropTypes.string,
quote: PropTypes.string,
2020-03-27 13:59:38 -07:00
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', {
icon: require('@tabler/icons/icons/trash.svg'),
heading: <FormattedMessage id='confirmations.delete.heading' defaultMessage='Delete post' />,
2020-03-27 13:59:38 -07:00
message: <FormattedMessage id='confirmations.delete.message' defaultMessage='Are you sure you want to delete this post?' />,
confirm: intl.formatMessage(messages.confirm),
onConfirm: () => {
dispatch(closeModal('COMPOSE'));
dispatch(cancelReplyCompose());
},
2020-03-27 13:59:38 -07:00
}));
2020-04-14 11:44:40 -07:00
} else {
2020-03-27 13:59:38 -07:00
onClose('COMPOSE');
}
};
renderTitle = () => {
const { privacy, inReplyTo, quote } = this.props;
if (privacy === 'direct') {
return <FormattedMessage id='navigation_bar.compose_direct' defaultMessage='Direct message' />;
} else if (inReplyTo) {
return <FormattedMessage id='navigation_bar.compose_reply' defaultMessage='Reply to post' />;
} else if (quote) {
return <FormattedMessage id='navigation_bar.compose_quote' defaultMessage='Quote post' />;
} else {
return <FormattedMessage id='navigation_bar.compose' defaultMessage='Compose new post' />;
}
}
render() {
2020-03-27 13:59:38 -07:00
return (
2022-03-21 11:09:01 -07:00
<Modal
title={this.renderTitle()}
onClose={this.onClickClose}
>
<ComposeFormContainer />
</Modal>
2020-03-27 13:59:38 -07:00
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}
export default injectIntl(connect(mapStateToProps)(ComposeModal));