From 02284a540841639e9a20560db909c529c768ccb7 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Fri, 5 Oct 2018 16:41:46 +0200 Subject: [PATCH] Add a confirmation dialog when hitting reply and the compose box isn't empty Fixes #878 --- app/javascript/mastodon/components/status.js | 5 ++++- .../mastodon/components/status_action_bar.js | 4 +++- .../mastodon/containers/status_container.js | 15 +++++++++++++-- app/javascript/mastodon/features/status/index.js | 15 ++++++++++++++- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/components/status.js b/app/javascript/mastodon/components/status.js index 90c689a75ae062..acc67757292d24 100644 --- a/app/javascript/mastodon/components/status.js +++ b/app/javascript/mastodon/components/status.js @@ -45,6 +45,7 @@ class Status extends ImmutablePureComponent { static propTypes = { status: ImmutablePropTypes.map, account: ImmutablePropTypes.map, + askReplyConfirmation: PropTypes.bool, onReply: PropTypes.func, onFavourite: PropTypes.func, onReblog: PropTypes.func, @@ -71,6 +72,7 @@ class Status extends ImmutablePureComponent { 'account', 'muted', 'hidden', + 'askReplyConfirmation', ] handleClick = () => { @@ -107,8 +109,9 @@ class Status extends ImmutablePureComponent { } handleHotkeyReply = e => { + let { onReply, askReplyConfirmation } = this.props; e.preventDefault(); - this.props.onReply(this._properStatus(), this.context.router.history); + onReply(this._properStatus(), this.context.router.history, askReplyConfirmation); } handleHotkeyFavourite = () => { diff --git a/app/javascript/mastodon/components/status_action_bar.js b/app/javascript/mastodon/components/status_action_bar.js index e7e5b0a6c02b14..7b4b3f0693ea9e 100644 --- a/app/javascript/mastodon/components/status_action_bar.js +++ b/app/javascript/mastodon/components/status_action_bar.js @@ -65,6 +65,7 @@ class StatusActionBar extends ImmutablePureComponent { onPin: PropTypes.func, withDismiss: PropTypes.bool, intl: PropTypes.object.isRequired, + askReplyConfirmation: PropTypes.bool, }; // Avoid checking props that are functions (and whose equality will always @@ -75,7 +76,8 @@ class StatusActionBar extends ImmutablePureComponent { ] handleReplyClick = () => { - this.props.onReply(this.props.status, this.context.router.history); + let { askReplyConfirmation, onReply } = this.props; + onReply(this.props.status, this.context.router.history, askReplyConfirmation); } handleShareClick = () => { diff --git a/app/javascript/mastodon/containers/status_container.js b/app/javascript/mastodon/containers/status_container.js index bbc0d5e96854be..3181d8a1eadf37 100644 --- a/app/javascript/mastodon/containers/status_container.js +++ b/app/javascript/mastodon/containers/status_container.js @@ -36,6 +36,8 @@ const messages = defineMessages({ redraftConfirm: { id: 'confirmations.redraft.confirm', defaultMessage: 'Delete & redraft' }, redraftMessage: { id: 'confirmations.redraft.message', defaultMessage: 'Are you sure you want to delete this status and re-draft it? Favourites and boosts will be lost, and replies to the original post will be orphaned.' }, blockConfirm: { id: 'confirmations.block.confirm', defaultMessage: 'Block' }, + replyConfirm: { id: 'confirmations.reply.confirm', defaultMessage: 'Reply' }, + replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' }, }); const makeMapStateToProps = () => { @@ -43,6 +45,7 @@ const makeMapStateToProps = () => { const mapStateToProps = (state, props) => ({ status: getStatus(state, props), + askReplyConfirmation: state.getIn(['compose', 'text']).trim().length !== 0, }); return mapStateToProps; @@ -50,8 +53,16 @@ const makeMapStateToProps = () => { const mapDispatchToProps = (dispatch, { intl }) => ({ - onReply (status, router) { - dispatch(replyCompose(status, router)); + onReply (status, router, confirm = false) { + if (confirm) { + dispatch(openModal('CONFIRM', { + message: intl.formatMessage(messages.replyMessage), + confirm: intl.formatMessage(messages.replyConfirm), + onConfirm: () => dispatch(replyCompose(status, router)), + })); + } else { + dispatch(replyCompose(status, router)); + } }, onModalReblog (status) { diff --git a/app/javascript/mastodon/features/status/index.js b/app/javascript/mastodon/features/status/index.js index 7d1bc2ca488a0c..2cd17b805121bb 100644 --- a/app/javascript/mastodon/features/status/index.js +++ b/app/javascript/mastodon/features/status/index.js @@ -54,6 +54,8 @@ const messages = defineMessages({ revealAll: { id: 'status.show_more_all', defaultMessage: 'Show more for all' }, hideAll: { id: 'status.show_less_all', defaultMessage: 'Show less for all' }, detailedStatus: { id: 'status.detailed_status', defaultMessage: 'Detailed conversation view' }, + replyConfirm: { id: 'confirmations.reply.confirm', defaultMessage: 'Reply' }, + replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' }, }); const makeMapStateToProps = () => { @@ -98,6 +100,7 @@ const makeMapStateToProps = () => { status, ancestorsIds, descendantsIds, + askReplyConfirmation: state.getIn(['compose', 'text']).trim().length !== 0, }; }; @@ -119,6 +122,7 @@ class Status extends ImmutablePureComponent { ancestorsIds: ImmutablePropTypes.list, descendantsIds: ImmutablePropTypes.list, intl: PropTypes.object.isRequired, + askReplyConfirmation: PropTypes.bool, }; state = { @@ -157,7 +161,16 @@ class Status extends ImmutablePureComponent { } handleReplyClick = (status) => { - this.props.dispatch(replyCompose(status, this.context.router.history)); + let { askReplyConfirmation, dispatch, intl } = this.props; + if (askReplyConfirmation) { + dispatch(openModal('CONFIRM', { + message: intl.formatMessage(messages.replyMessage), + confirm: intl.formatMessage(messages.replyConfirm), + onConfirm: () => dispatch(replyCompose(status, this.context.router.history)), + })); + } else { + dispatch(replyCompose(status, this.context.router.history)); + } } handleModalReblog = (status) => {