From 500165c478df4eb7edbac9df4313bfdfa53693f5 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Apr 2020 14:41:13 -0500 Subject: [PATCH] Refactor modal settings --- app/gabsocial/containers/account_container.js | 26 +++++++------ app/gabsocial/containers/status_container.js | 35 ++++++++++------- .../containers/header_container.js | 26 +++++++------ .../containers/notification_container.js | 18 +++++---- .../containers/detailed_status_container.js | 39 +++++++++++-------- app/gabsocial/features/status/index.js | 39 +++++++++++-------- 6 files changed, 102 insertions(+), 81 deletions(-) diff --git a/app/gabsocial/containers/account_container.js b/app/gabsocial/containers/account_container.js index 233db497f..e6d20b804 100644 --- a/app/gabsocial/containers/account_container.js +++ b/app/gabsocial/containers/account_container.js @@ -13,7 +13,6 @@ import { } from '../actions/accounts'; import { openModal } from '../actions/modal'; import { initMuteModal } from '../actions/mutes'; -import { unfollowModal } from '../initial_state'; const messages = defineMessages({ unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' }, @@ -32,19 +31,22 @@ const makeMapStateToProps = () => { const mapDispatchToProps = (dispatch, { intl }) => ({ onFollow(account) { - if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { - if (unfollowModal) { - dispatch(openModal('CONFIRM', { - message: @{account.get('acct')} }} />, - confirm: intl.formatMessage(messages.unfollowConfirm), - onConfirm: () => dispatch(unfollowAccount(account.get('id'))), - })); + dispatch((_, getState) => { + const unfollowModal = getState().getIn(['settings', 'unfollowModal']); + if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { + if (unfollowModal) { + dispatch(openModal('CONFIRM', { + message: @{account.get('acct')} }} />, + confirm: intl.formatMessage(messages.unfollowConfirm), + onConfirm: () => dispatch(unfollowAccount(account.get('id'))), + })); + } else { + dispatch(unfollowAccount(account.get('id'))); + } } else { - dispatch(unfollowAccount(account.get('id'))); + dispatch(followAccount(account.get('id'))); } - } else { - dispatch(followAccount(account.get('id'))); - } + }); }, onBlock(account) { diff --git a/app/gabsocial/containers/status_container.js b/app/gabsocial/containers/status_container.js index 3038a96b1..264380be8 100644 --- a/app/gabsocial/containers/status_container.js +++ b/app/gabsocial/containers/status_container.js @@ -27,7 +27,6 @@ import { initMuteModal } from '../actions/mutes'; import { initReport } from '../actions/reports'; import { openModal } from '../actions/modal'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; -import { boostModal, deleteModal } from '../initial_state'; import { showAlertForError } from '../actions/alerts'; import { createRemovedAccount, @@ -81,11 +80,14 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ }, onReblog(status, e) { - if (e.shiftKey || !boostModal) { - this.onModalReblog(status); - } else { - dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); - } + dispatch((_, getState) => { + const boostModal = getState().getIn(['settings', 'boostModal']); + if (e.shiftKey || !boostModal) { + this.onModalReblog(status); + } else { + dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); + } + }); }, onFavourite(status) { @@ -112,15 +114,18 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ }, onDelete(status, history, withRedraft = false) { - if (!deleteModal) { - dispatch(deleteStatus(status.get('id'), history, withRedraft)); - } else { - dispatch(openModal('CONFIRM', { - message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), - confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), - onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), - })); - } + dispatch((_, getState) => { + const deleteModal = getState().getIn(['settings', 'deleteModal']); + if (!deleteModal) { + dispatch(deleteStatus(status.get('id'), history, withRedraft)); + } else { + dispatch(openModal('CONFIRM', { + message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), + confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), + onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), + })); + } + }); }, onDirect(account, router) { diff --git a/app/gabsocial/features/account_timeline/containers/header_container.js b/app/gabsocial/features/account_timeline/containers/header_container.js index d7cf41f78..fbd110663 100644 --- a/app/gabsocial/features/account_timeline/containers/header_container.js +++ b/app/gabsocial/features/account_timeline/containers/header_container.js @@ -20,7 +20,6 @@ import { initReport } from '../../../actions/reports'; import { openModal } from '../../../actions/modal'; import { blockDomain, unblockDomain } from '../../../actions/domain_blocks'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; -import { unfollowModal } from '../../../initial_state'; import { List as ImmutableList } from 'immutable'; const messages = defineMessages({ @@ -45,19 +44,22 @@ const makeMapStateToProps = () => { const mapDispatchToProps = (dispatch, { intl }) => ({ onFollow(account) { - if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { - if (unfollowModal) { - dispatch(openModal('CONFIRM', { - message: @{account.get('acct')} }} />, - confirm: intl.formatMessage(messages.unfollowConfirm), - onConfirm: () => dispatch(unfollowAccount(account.get('id'))), - })); + dispatch((_, getState) => { + const unfollowModal = getState().getIn(['settings', 'unfollowModal']); + if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { + if (unfollowModal) { + dispatch(openModal('CONFIRM', { + message: @{account.get('acct')} }} />, + confirm: intl.formatMessage(messages.unfollowConfirm), + onConfirm: () => dispatch(unfollowAccount(account.get('id'))), + })); + } else { + dispatch(unfollowAccount(account.get('id'))); + } } else { - dispatch(unfollowAccount(account.get('id'))); + dispatch(followAccount(account.get('id'))); } - } else { - dispatch(followAccount(account.get('id'))); - } + }); }, onBlock(account) { diff --git a/app/gabsocial/features/notifications/containers/notification_container.js b/app/gabsocial/features/notifications/containers/notification_container.js index 1f225df5d..f2695e6d7 100644 --- a/app/gabsocial/features/notifications/containers/notification_container.js +++ b/app/gabsocial/features/notifications/containers/notification_container.js @@ -13,7 +13,6 @@ import { hideStatus, revealStatus, } from '../../../actions/statuses'; -import { boostModal } from '../../../initial_state'; const makeMapStateToProps = () => { const getNotification = makeGetNotification(); @@ -40,15 +39,18 @@ const mapDispatchToProps = dispatch => ({ }, onReblog(status, e) { - if (status.get('reblogged')) { - dispatch(unreblog(status)); - } else { - if (e.shiftKey || !boostModal) { - this.onModalReblog(status); + dispatch((_, getState) => { + const boostModal = getState().getIn(['settings', 'boostModal']); + if (status.get('reblogged')) { + dispatch(unreblog(status)); } else { - dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); + if (e.shiftKey || !boostModal) { + this.onModalReblog(status); + } else { + dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); + } } - } + }); }, onFavourite(status) { diff --git a/app/gabsocial/features/status/containers/detailed_status_container.js b/app/gabsocial/features/status/containers/detailed_status_container.js index 158156748..684614532 100644 --- a/app/gabsocial/features/status/containers/detailed_status_container.js +++ b/app/gabsocial/features/status/containers/detailed_status_container.js @@ -27,7 +27,6 @@ import { initMuteModal } from '../../../actions/mutes'; import { initReport } from '../../../actions/reports'; import { openModal } from '../../../actions/modal'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; -import { boostModal, deleteModal } from '../../../initial_state'; import { showAlertForError } from '../../../actions/alerts'; const messages = defineMessages({ @@ -74,15 +73,18 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ }, onReblog(status, e) { - if (status.get('reblogged')) { - dispatch(unreblog(status)); - } else { - if (e.shiftKey || !boostModal) { - this.onModalReblog(status); + dispatch((_, getState) => { + const boostModal = getState().getIn(['settings', 'boostModal']); + if (status.get('reblogged')) { + dispatch(unreblog(status)); } else { - dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); + if (e.shiftKey || !boostModal) { + this.onModalReblog(status); + } else { + dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); + } } - } + }); }, onFavourite(status) { @@ -109,15 +111,18 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ }, onDelete(status, history, withRedraft = false) { - if (!deleteModal) { - dispatch(deleteStatus(status.get('id'), history, withRedraft)); - } else { - dispatch(openModal('CONFIRM', { - message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), - confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), - onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), - })); - } + dispatch((_, getState) => { + const deleteModal = getState().getIn(['settings', 'deleteModal']); + if (!deleteModal) { + dispatch(deleteStatus(status.get('id'), history, withRedraft)); + } else { + dispatch(openModal('CONFIRM', { + message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), + confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), + onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), + })); + } + }); }, onDirect(account, router) { diff --git a/app/gabsocial/features/status/index.js b/app/gabsocial/features/status/index.js index 2dd149b5e..ce431c5b4 100644 --- a/app/gabsocial/features/status/index.js +++ b/app/gabsocial/features/status/index.js @@ -39,7 +39,6 @@ import { openModal } from '../../actions/modal'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import { HotKeys } from 'react-hotkeys'; -import { boostModal, deleteModal } from '../../initial_state'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen'; import { textForScreenReader, defaultMediaVisibility } from '../../components/status'; import Icon from 'gabsocial/components/icon'; @@ -195,29 +194,35 @@ class Status extends ImmutablePureComponent { } handleReblogClick = (status, e) => { - if (status.get('reblogged')) { - this.props.dispatch(unreblog(status)); - } else { - if ((e && e.shiftKey) || !boostModal) { - this.handleModalReblog(status); + this.props.dispatch((_, getState) => { + const boostModal = getState().getIn(['settings', 'boostModal']); + if (status.get('reblogged')) { + this.props.dispatch(unreblog(status)); } else { - this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog })); + if ((e && e.shiftKey) || !boostModal) { + this.handleModalReblog(status); + } else { + this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog })); + } } - } + }); } handleDeleteClick = (status, history, withRedraft = false) => { const { dispatch, intl } = this.props; - if (!deleteModal) { - dispatch(deleteStatus(status.get('id'), history, withRedraft)); - } else { - dispatch(openModal('CONFIRM', { - message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), - confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), - onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), - })); - } + this.props.dispatch((_, getState) => { + const deleteModal = getState().getIn(['settings', 'deleteModal']); + if (!deleteModal) { + dispatch(deleteStatus(status.get('id'), history, withRedraft)); + } else { + dispatch(openModal('CONFIRM', { + message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage), + confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm), + onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), + })); + } + }); } handleDirectClick = (account, router) => {