import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { cancelReplyCompose } from 'soapbox/actions/compose'; import { openModal, closeModal } from 'soapbox/actions/modals'; import { checkComposeContent } from 'soapbox/components/modal_root'; import { Modal } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import ComposeFormContainer from '../../compose/containers/compose_form_container'; const messages = defineMessages({ close: { id: 'lightbox.close', defaultMessage: 'Close' }, confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, cancelEditing: { id: 'confirmations.cancel_editing.confirm', defaultMessage: 'Cancel editing' }, }); interface IComposeModal { onClose: (type?: string) => void, } const ComposeModal: React.FC = ({ onClose }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const statusId = useAppSelector((state) => state.compose.id); const hasComposeContent = useAppSelector((state) => checkComposeContent(state.compose)); const privacy = useAppSelector((state) => state.compose.privacy); const inReplyTo = useAppSelector((state) => state.compose.in_reply_to); const quote = useAppSelector((state) => state.compose.quote); const onClickClose = () => { if (hasComposeContent) { dispatch(openModal('CONFIRM', { icon: require('@tabler/icons/trash.svg'), heading: statusId ? : , message: statusId ? : , confirm: intl.formatMessage(statusId ? messages.cancelEditing : messages.confirm), onConfirm: () => { dispatch(closeModal('COMPOSE')); dispatch(cancelReplyCompose()); }, })); } else { onClose('COMPOSE'); } }; const renderTitle = () => { if (statusId) { return ; } else if (privacy === 'direct') { return ; } else if (inReplyTo) { return ; } else if (quote) { return ; } else { return ; } }; return ( ); }; export default ComposeModal;