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';
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,6 +31,8 @@ const makeMapStateToProps = () => {
const mapDispatchToProps = (dispatch, { intl }) => ({
onFollow(account) {
dispatch((_, getState) => {
const unfollowModal = getState().getIn(['settings', 'unfollowModal']);
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (unfollowModal) {
dispatch(openModal('CONFIRM', {
@ -45,6 +46,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} else {
dispatch(followAccount(account.get('id')));
}
});
},
onBlock(account) {

View file

@ -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) {
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,6 +114,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
},
onDelete(status, history, withRedraft = false) {
dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else {
@ -121,6 +125,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
}));
}
});
},
onDirect(account, router) {

View file

@ -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,6 +44,8 @@ const makeMapStateToProps = () => {
const mapDispatchToProps = (dispatch, { intl }) => ({
onFollow(account) {
dispatch((_, getState) => {
const unfollowModal = getState().getIn(['settings', 'unfollowModal']);
if (account.getIn(['relationship', 'following']) || account.getIn(['relationship', 'requested'])) {
if (unfollowModal) {
dispatch(openModal('CONFIRM', {
@ -58,6 +59,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
} else {
dispatch(followAccount(account.get('id')));
}
});
},
onBlock(account) {

View file

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

View file

@ -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,6 +73,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
},
onReblog(status, e) {
dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
if (status.get('reblogged')) {
dispatch(unreblog(status));
} else {
@ -83,6 +84,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
dispatch(openModal('BOOST', { status, onReblog: this.onModalReblog }));
}
}
});
},
onFavourite(status) {
@ -109,6 +111,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
},
onDelete(status, history, withRedraft = false) {
dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else {
@ -118,6 +122,7 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
}));
}
});
},
onDirect(account, router) {

View file

@ -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,6 +194,8 @@ class Status extends ImmutablePureComponent {
}
handleReblogClick = (status, e) => {
this.props.dispatch((_, getState) => {
const boostModal = getState().getIn(['settings', 'boostModal']);
if (status.get('reblogged')) {
this.props.dispatch(unreblog(status));
} else {
@ -204,11 +205,14 @@ class Status extends ImmutablePureComponent {
this.props.dispatch(openModal('BOOST', { status, onReblog: this.handleModalReblog }));
}
}
});
}
handleDeleteClick = (status, history, withRedraft = false) => {
const { dispatch, intl } = this.props;
this.props.dispatch((_, getState) => {
const deleteModal = getState().getIn(['settings', 'deleteModal']);
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
} else {
@ -218,6 +222,7 @@ class Status extends ImmutablePureComponent {
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
}));
}
});
}
handleDirectClick = (account, router) => {