Refactor modal settings

This commit is contained in:
Alex Gleason 2020-04-21 14:41:13 -05:00
parent cafa014018
commit 500165c478
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
6 changed files with 102 additions and 81 deletions

View File

@ -13,7 +13,6 @@ import {
} from '../actions/accounts'; } from '../actions/accounts';
import { openModal } from '../actions/modal'; import { openModal } from '../actions/modal';
import { initMuteModal } from '../actions/mutes'; import { initMuteModal } from '../actions/mutes';
import { unfollowModal } from '../initial_state';
const messages = defineMessages({ const messages = defineMessages({
unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' }, unfollowConfirm: { id: 'confirmations.unfollow.confirm', defaultMessage: 'Unfollow' },
@ -32,6 +31,8 @@ const makeMapStateToProps = () => {
const mapDispatchToProps = (dispatch, { intl }) => ({ const mapDispatchToProps = (dispatch, { intl }) => ({
onFollow(account) { onFollow(account) {
dispatch((_, getState) => {
const unfollowModal = getState().getIn(['settings', 'unfollowModal']);
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (unfollowModal) { if (unfollowModal) {
dispatch(openModal('CONFIRM', { dispatch(openModal('CONFIRM', {
@ -45,6 +46,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} else { } else {
dispatch(followAccount(account.get('id'))); dispatch(followAccount(account.get('id')));
} }
});
}, },
onBlock(account) { onBlock(account) {

View File

@ -27,7 +27,6 @@ import { initMuteModal } from '../actions/mutes';
import { initReport } from '../actions/reports'; import { initReport } from '../actions/reports';
import { openModal } from '../actions/modal'; import { openModal } from '../actions/modal';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { boostModal, deleteModal } from '../initial_state';
import { showAlertForError } from '../actions/alerts'; import { showAlertForError } from '../actions/alerts';
import { import {
createRemovedAccount, createRemovedAccount,
@ -81,11 +80,14 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onReblog(status, e) { onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
if (e.shiftKey || !boostModal) { if (e.shiftKey || !boostModal) {
this.onModalReblog(status); this.onModalReblog(status);
} else { } else {
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
} }
});
}, },
onFavourite(status) { onFavourite(status) {
@ -112,6 +114,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onDelete(status, history, withRedraft = false) { onDelete(status, history, withRedraft = false) {
dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
if (!deleteModal) { if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft)); dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else { } else {
@ -121,6 +125,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
})); }));
} }
});
}, },
onDirect(account, router) { onDirect(account, router) {

View File

@ -20,7 +20,6 @@ import { initReport } from '../../../actions/reports';
import { openModal } from '../../../actions/modal'; import { openModal } from '../../../actions/modal';
import { blockDomain, unblockDomain } from '../../../actions/domain_blocks'; import { blockDomain, unblockDomain } from '../../../actions/domain_blocks';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { unfollowModal } from '../../../initial_state';
import { List as ImmutableList } from 'immutable'; import { List as ImmutableList } from 'immutable';
const messages = defineMessages({ const messages = defineMessages({
@ -45,6 +44,8 @@ const makeMapStateToProps = () => {
const mapDispatchToProps = (dispatch, { intl }) => ({ const mapDispatchToProps = (dispatch, { intl }) => ({
onFollow(account) { onFollow(account) {
dispatch((_, getState) => {
const unfollowModal = getState().getIn(['settings', 'unfollowModal']);
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) { if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (unfollowModal) { if (unfollowModal) {
dispatch(openModal('CONFIRM', { dispatch(openModal('CONFIRM', {
@ -58,6 +59,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} else { } else {
dispatch(followAccount(account.get('id'))); dispatch(followAccount(account.get('id')));
} }
});
}, },
onBlock(account) { onBlock(account) {

View File

@ -13,7 +13,6 @@ import {
hideStatus, hideStatus,
revealStatus, revealStatus,
} from '../../../actions/statuses'; } from '../../../actions/statuses';
import { boostModal } from '../../../initial_state';
const makeMapStateToProps = () => { const makeMapStateToProps = () => {
const getNotification = makeGetNotification(); const getNotification = makeGetNotification();
@ -40,6 +39,8 @@ const mapDispatchToProps = dispatch => ({
}, },
onReblog(status, e) { onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
if (status.get('reblogged')) { if (status.get('reblogged')) {
dispatch(unreblog(status)); dispatch(unreblog(status));
} else { } else {
@ -49,6 +50,7 @@ const mapDispatchToProps = dispatch => ({
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
} }
} }
});
}, },
onFavourite(status) { onFavourite(status) {

View File

@ -27,7 +27,6 @@ import { initMuteModal } from '../../../actions/mutes';
import { initReport } from '../../../actions/reports'; import { initReport } from '../../../actions/reports';
import { openModal } from '../../../actions/modal'; import { openModal } from '../../../actions/modal';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { boostModal, deleteModal } from '../../../initial_state';
import { showAlertForError } from '../../../actions/alerts'; import { showAlertForError } from '../../../actions/alerts';
const messages = defineMessages({ const messages = defineMessages({
@ -74,6 +73,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onReblog(status, e) { onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
if (status.get('reblogged')) { if (status.get('reblogged')) {
dispatch(unreblog(status)); dispatch(unreblog(status));
} else { } else {
@ -83,6 +84,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog })); dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
} }
} }
});
}, },
onFavourite(status) { onFavourite(status) {
@ -109,6 +111,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}, },
onDelete(status, history, withRedraft = false) { onDelete(status, history, withRedraft = false) {
dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
if (!deleteModal) { if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft)); dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else { } else {
@ -118,6 +122,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
})); }));
} }
});
}, },
onDirect(account, router) { onDirect(account, router) {

View File

@ -39,7 +39,6 @@ import { openModal } from '../../actions/modal';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import ImmutablePureComponent from 'react-immutable-pure-component'; import ImmutablePureComponent from 'react-immutable-pure-component';
import { HotKeys } from 'react-hotkeys'; import { HotKeys } from 'react-hotkeys';
import { boostModal, deleteModal } from '../../initial_state';
import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen'; import { attachFullscreenListener, detachFullscreenListener, isFullscreen } from '../ui/util/fullscreen';
import { textForScreenReader, defaultMediaVisibility } from '../../components/status'; import { textForScreenReader, defaultMediaVisibility } from '../../components/status';
import Icon from 'gabsocial/components/icon'; import Icon from 'gabsocial/components/icon';
@ -195,6 +194,8 @@ class Status extends ImmutablePureComponent {
} }
handleReblogClick = (status, e) => { handleReblogClick = (status, e) => {
this.props.dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
if (status.get('reblogged')) { if (status.get('reblogged')) {
this.props.dispatch(unreblog(status)); this.props.dispatch(unreblog(status));
} else { } else {
@ -204,11 +205,14 @@ class Status extends ImmutablePureComponent {
this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog })); this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
} }
} }
});
} }
handleDeleteClick = (status, history, withRedraft = false) => { handleDeleteClick = (status, history, withRedraft = false) => {
const { dispatch, intl } = this.props; const { dispatch, intl } = this.props;
this.props.dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
if (!deleteModal) { if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft)); dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else { } else {
@ -218,6 +222,7 @@ class Status extends ImmutablePureComponent {
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)), onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
})); }));
} }
});
} }
handleDirectClick = (account, router) => { handleDirectClick = (account, router) => {