From 8aeeaa7244a0758987d9fb71f3aa5d493ccfc371 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Mon, 22 Jul 2019 23:01:12 -0400 Subject: [PATCH 1/3] Added type to modal_root base --- app/javascript/gabsocial/features/ui/components/modal_root.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/javascript/gabsocial/features/ui/components/modal_root.js b/app/javascript/gabsocial/features/ui/components/modal_root.js index 6cc325c2..c365f75f 100644 --- a/app/javascript/gabsocial/features/ui/components/modal_root.js +++ b/app/javascript/gabsocial/features/ui/components/modal_root.js @@ -77,7 +77,7 @@ export default class ModalRoot extends React.PureComponent { const visible = !!type; return ( - + {visible && ( {(SpecificComponent) => } From efd441d0ba4a6198fd2104eb605fe878a8f539d5 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Mon, 22 Jul 2019 23:02:14 -0400 Subject: [PATCH 2/3] Added onCancel function prop to confirmation_modal Added an optional function to call on confirmation modal --- .../gabsocial/features/ui/components/confirmation_modal.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/javascript/gabsocial/features/ui/components/confirmation_modal.js b/app/javascript/gabsocial/features/ui/components/confirmation_modal.js index 1227fa45..ef5428db 100644 --- a/app/javascript/gabsocial/features/ui/components/confirmation_modal.js +++ b/app/javascript/gabsocial/features/ui/components/confirmation_modal.js @@ -14,6 +14,7 @@ class ConfirmationModal extends React.PureComponent { secondary: PropTypes.string, onSecondary: PropTypes.func, intl: PropTypes.object.isRequired, + onCancel: PropTypes.func, }; componentDidMount() { @@ -31,7 +32,9 @@ class ConfirmationModal extends React.PureComponent { } handleCancel = () => { - this.props.onClose(); + const {onClose, onCancel} = this.props; + onClose(); + if (onCancel) onCancel(); } setRef = (c) => { From b61596b1a759e0c99e7146658f11db5c841fa143 Mon Sep 17 00:00:00 2001 From: mgabdev <> Date: Mon, 22 Jul 2019 23:10:05 -0400 Subject: [PATCH 3/3] Added confirmation to compose modal on close if has text Added to modal_root if modal type is compose Added to compose_modal Fixes: #51 --- .../gabsocial/components/modal_root.js | 53 +++++++++++++++++-- .../features/ui/components/compose_modal.js | 22 +++++++- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/app/javascript/gabsocial/components/modal_root.js b/app/javascript/gabsocial/components/modal_root.js index ef115657..fcc6278d 100644 --- a/app/javascript/gabsocial/components/modal_root.js +++ b/app/javascript/gabsocial/components/modal_root.js @@ -1,11 +1,37 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { injectIntl, FormattedMessage, defineMessages } from 'react-intl'; +import { connect } from 'react-redux'; +import { openModal } from '../actions/modal'; +import { cancelReplyCompose } from '../actions/compose'; -export default class ModalRoot extends React.PureComponent { +const messages = defineMessages({ + confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, +}); + +const mapStateToProps = state => ({ + composeText: state.getIn(['compose', 'text']), +}); + +const mapDispatchToProps = (dispatch) => ({ + onOpenModal(type, opts) { + dispatch(openModal(type, opts)); + }, + onCancelReplyCompose() { + dispatch(cancelReplyCompose()); + } +}); + +class ModalRoot extends React.PureComponent { static propTypes = { children: PropTypes.node, onClose: PropTypes.func.isRequired, + onOpenModal: PropTypes.func.isRequired, + onCancelReplyCompose: PropTypes.func.isRequired, + intl: PropTypes.object.isRequired, + composeText: PropTypes.string, + type: PropTypes.string, }; state = { @@ -17,10 +43,26 @@ export default class ModalRoot extends React.PureComponent { handleKeyUp = (e) => { if ((e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) && !!this.props.children) { - this.props.onClose(); + this.handleOnClose(); } } + handleOnClose = () => { + const { onOpenModal, composeText, onClose, intl, type, onCancelReplyCompose } = this.props; + + if (composeText && type == 'COMPOSE') { + onOpenModal('CONFIRM', { + message: , + confirm: intl.formatMessage(messages.confirm), + onConfirm: () => onCancelReplyCompose(), + onCancel: () => onOpenModal('COMPOSE'), + }); + } + else { + this.props.onClose(); + } + }; + componentDidMount () { window.addEventListener('keyup', this.handleKeyUp, false); } @@ -63,7 +105,7 @@ export default class ModalRoot extends React.PureComponent { } render () { - const { children, onClose } = this.props; + const { children } = this.props; const { revealed } = this.state; const visible = !!children; @@ -76,11 +118,12 @@ export default class ModalRoot extends React.PureComponent { return (
-
+
this.handleOnClose()} />
{children}
); } - } + +export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(ModalRoot)); diff --git a/app/javascript/gabsocial/features/ui/components/compose_modal.js b/app/javascript/gabsocial/features/ui/components/compose_modal.js index 638cdb0d..865bdec3 100644 --- a/app/javascript/gabsocial/features/ui/components/compose_modal.js +++ b/app/javascript/gabsocial/features/ui/components/compose_modal.js @@ -8,14 +8,18 @@ import Avatar from '../../../components/avatar'; import ImmutablePureComponent from 'react-immutable-pure-component'; import ComposeFormContainer from '../../compose/containers/compose_form_container'; import IconButton from 'gabsocial/components/icon_button'; +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 => { return { account: state.getIn(['accounts', me]), + composeText: state.getIn(['compose', 'text']), }; }; @@ -25,14 +29,28 @@ class ComposeModal extends ImmutablePureComponent { account: ImmutablePropTypes.map, intl: PropTypes.object.isRequired, onClose: PropTypes.func.isRequired, + composeText: PropTypes.string, + dispatch: PropTypes.func.isRequired, }; onClickClose = () => { - this.props.onClose('COMPOSE'); + const {composeText, dispatch, onClose, intl} = this.props; + + if (composeText) { + dispatch(openModal('CONFIRM', { + message: , + confirm: intl.formatMessage(messages.confirm), + onConfirm: () => dispatch(cancelReplyCompose()), + onCancel: () => dispatch(openModal('COMPOSE')), + })); + } + else { + onClose('COMPOSE'); + } }; render () { - const { intl, onClose, account } = this.props; + const { intl, account } = this.props; return (