[Glitch] Remove routerHistory parameters from composer actions

Port e768b23aa9 to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
Claire 2024-07-19 17:26:44 +02:00
parent 9f05a06dee
commit 95984b729a
18 changed files with 94 additions and 104 deletions

View File

@ -4,6 +4,7 @@ import axios from 'axios';
import { throttle } from 'lodash';
import api from 'flavours/glitch/api';
import { browserHistory } from 'flavours/glitch/components/router';
import { search as emojiSearch } from 'flavours/glitch/features/emoji/emoji_mart_search_light';
import { tagHistory } from 'flavours/glitch/settings';
import { recoverHashtags } from 'flavours/glitch/utils/hashtag';
@ -94,9 +95,9 @@ const messages = defineMessages({
saved: { id: 'compose.saved.body', defaultMessage: 'Post saved.' },
});
export const ensureComposeIsVisible = (getState, routerHistory) => {
export const ensureComposeIsVisible = (getState) => {
if (!getState().getIn(['compose', 'mounted'])) {
routerHistory.push('/publish');
browserHistory.push('/publish');
}
};
@ -117,7 +118,7 @@ export function changeCompose(text) {
};
}
export function replyCompose(status, routerHistory) {
export function replyCompose(status) {
return (dispatch, getState) => {
const prependCWRe = getState().getIn(['local_settings', 'prepend_cw_re']);
dispatch({
@ -126,7 +127,7 @@ export function replyCompose(status, routerHistory) {
prependCWRe: prependCWRe,
});
ensureComposeIsVisible(getState, routerHistory);
ensureComposeIsVisible(getState);
};
}
@ -142,38 +143,38 @@ export function resetCompose() {
};
}
export const focusCompose = (routerHistory, defaultText) => (dispatch, getState) => {
export const focusCompose = (defaultText) => (dispatch, getState) => {
dispatch({
type: COMPOSE_FOCUS,
defaultText,
});
ensureComposeIsVisible(getState, routerHistory);
ensureComposeIsVisible(getState);
};
export function mentionCompose(account, routerHistory) {
export function mentionCompose(account) {
return (dispatch, getState) => {
dispatch({
type: COMPOSE_MENTION,
account: account,
});
ensureComposeIsVisible(getState, routerHistory);
ensureComposeIsVisible(getState);
};
}
export function directCompose(account, routerHistory) {
export function directCompose(account) {
return (dispatch, getState) => {
dispatch({
type: COMPOSE_DIRECT,
account: account,
});
ensureComposeIsVisible(getState, routerHistory);
ensureComposeIsVisible(getState);
};
}
export function submitCompose(routerHistory, overridePrivacy = null) {
export function submitCompose(overridePrivacy = null) {
return function (dispatch, getState) {
let status = getState().getIn(['compose', 'text'], '');
const media = getState().getIn(['compose', 'media_attachments']);
@ -230,11 +231,10 @@ export function submitCompose(routerHistory, overridePrivacy = null) {
'Idempotency-Key': getState().getIn(['compose', 'idempotencyKey']),
},
}).then(function (response) {
if (routerHistory
&& (routerHistory.location.pathname === '/publish' || routerHistory.location.pathname === '/statuses/new')
if ((browserHistory.location.pathname === '/publish' || browserHistory.location.pathname === '/statuses/new')
&& window.history.state
&& !getState().getIn(['compose', 'advanced_options', 'threaded_mode'])) {
routerHistory.goBack();
browserHistory.goBack();
}
dispatch(insertIntoTagHistory(response.data.tags, status));
@ -272,7 +272,7 @@ export function submitCompose(routerHistory, overridePrivacy = null) {
message: statusId === null ? messages.published : messages.saved,
action: messages.open,
dismissAfter: 10000,
onClick: () => routerHistory.push(`/@${response.data.account.username}/${response.data.id}`),
onClick: () => browserHistory.push(`/@${response.data.account.username}/${response.data.id}`),
}));
}
}).catch(function (error) {

View File

@ -94,7 +94,7 @@ export function redraft(status, raw_text, content_type) {
};
}
export const editStatus = (id, routerHistory) => (dispatch, getState) => {
export const editStatus = (id) => (dispatch, getState) => {
let status = getState().getIn(['statuses', id]);
if (status.get('poll')) {
@ -105,7 +105,7 @@ export const editStatus = (id, routerHistory) => (dispatch, getState) => {
api().get(`/api/v1/statuses/${id}/source`).then(response => {
dispatch(fetchStatusSourceSuccess());
ensureComposeIsVisible(getState, routerHistory);
ensureComposeIsVisible(getState);
dispatch(setComposeToStatus(status, response.data.text, response.data.spoiler_text, response.data.content_type));
}).catch(error => {
dispatch(fetchStatusSourceFail(error));
@ -125,7 +125,7 @@ export const fetchStatusSourceFail = error => ({
error,
});
export function deleteStatus(id, routerHistory, withRedraft = false) {
export function deleteStatus(id, withRedraft = false) {
return (dispatch, getState) => {
let status = getState().getIn(['statuses', id]);
@ -142,7 +142,7 @@ export function deleteStatus(id, routerHistory, withRedraft = false) {
if (withRedraft) {
dispatch(redraft(status, response.data.text, response.data.content_type));
ensureComposeIsVisible(getState, routerHistory);
ensureComposeIsVisible(getState);
}
}).catch(error => {
dispatch(deleteStatusFail(id, error));

View File

@ -22,7 +22,7 @@ type LocationState = MastodonLocationState | null | undefined;
type HistoryPath = Path | LocationDescriptor<LocationState>;
const browserHistory = createBrowserHistory<LocationState>();
export const browserHistory = createBrowserHistory<LocationState>();
const originalPush = browserHistory.push.bind(browserHistory);
const originalReplace = browserHistory.replace.bind(browserHistory);

View File

@ -442,7 +442,7 @@ class Status extends ImmutablePureComponent {
handleHotkeyReply = e => {
e.preventDefault();
this.props.onReply(this.props.status, this.props.history);
this.props.onReply(this.props.status);
};
handleHotkeyFavourite = (e) => {
@ -459,7 +459,7 @@ class Status extends ImmutablePureComponent {
handleHotkeyMention = e => {
e.preventDefault();
this.props.onMention(this.props.status.get('account'), this.props.history);
this.props.onMention(this.props.status.get('account'));
};
handleHotkeyOpen = () => {

View File

@ -108,7 +108,7 @@ class StatusActionBar extends ImmutablePureComponent {
const { signedIn } = this.props.identity;
if (signedIn) {
this.props.onReply(this.props.status, this.props.history);
this.props.onReply(this.props.status);
} else {
this.props.onInteractionModal('reply', this.props.status);
}
@ -145,15 +145,15 @@ class StatusActionBar extends ImmutablePureComponent {
};
handleDeleteClick = () => {
this.props.onDelete(this.props.status, this.props.history);
this.props.onDelete(this.props.status);
};
handleRedraftClick = () => {
this.props.onDelete(this.props.status, this.props.history, true);
this.props.onDelete(this.props.status, true);
};
handleEditClick = () => {
this.props.onEdit(this.props.status, this.props.history);
this.props.onEdit(this.props.status);
};
handlePinClick = () => {
@ -161,11 +161,11 @@ class StatusActionBar extends ImmutablePureComponent {
};
handleMentionClick = () => {
this.props.onMention(this.props.status.get('account'), this.props.history);
this.props.onMention(this.props.status.get('account'));
};
handleDirectClick = () => {
this.props.onDirect(this.props.status.get('account'), this.props.history);
this.props.onDirect(this.props.status.get('account'));
};
handleMuteClick = () => {

View File

@ -93,7 +93,7 @@ const makeMapStateToProps = () => {
const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
onReply (status, router) {
onReply (status) {
dispatch((_, getState) => {
let state = getState();
@ -104,11 +104,11 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
message: intl.formatMessage(messages.replyMessage),
confirm: intl.formatMessage(messages.replyConfirm),
onDoNotAsk: () => dispatch(changeLocalSetting(['confirm_before_clearing_draft'], false)),
onConfirm: () => dispatch(replyCompose(status, router)),
onConfirm: () => dispatch(replyCompose(status)),
},
}));
} else {
dispatch(replyCompose(status, router));
dispatch(replyCompose(status));
}
});
},
@ -182,22 +182,22 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
}));
},
onDelete (status, history, withRedraft = false) {
onDelete (status, withRedraft = false) {
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
dispatch(deleteStatus(status.get('id'), withRedraft));
} else {
dispatch(openModal({
modalType: 'CONFIRM',
modalProps: {
message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
onConfirm: () => dispatch(deleteStatus(status.get('id'), withRedraft)),
},
}));
}
},
onEdit (status, history) {
onEdit (status) {
dispatch((_, getState) => {
let state = getState();
if (state.getIn(['compose', 'text']).trim().length !== 0) {
@ -206,11 +206,11 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
modalProps: {
message: intl.formatMessage(messages.editMessage),
confirm: intl.formatMessage(messages.editConfirm),
onConfirm: () => dispatch(editStatus(status.get('id'), history)),
onConfirm: () => dispatch(editStatus(status.get('id'))),
},
}));
} else {
dispatch(editStatus(status.get('id'), history));
dispatch(editStatus(status.get('id')));
}
});
},
@ -223,12 +223,12 @@ const mapDispatchToProps = (dispatch, { intl, contextType }) => ({
}
},
onDirect (account, router) {
dispatch(directCompose(account, router));
onDirect (account) {
dispatch(directCompose(account));
},
onMention (account, router) {
dispatch(mentionCompose(account, router));
onMention (account) {
dispatch(mentionCompose(account));
},
onOpenMedia (statusId, media, index, lang) {

View File

@ -2,13 +2,11 @@ import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';
import { NavLink, withRouter } from 'react-router-dom';
import { NavLink } from 'react-router-dom';
import ImmutablePropTypes from 'react-immutable-proptypes';
import ImmutablePureComponent from 'react-immutable-pure-component';
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
import ActionBar from '../../account/components/action_bar';
import InnerHeader from '../../account/components/header';
@ -36,7 +34,6 @@ class Header extends ImmutablePureComponent {
hideTabs: PropTypes.bool,
domain: PropTypes.string.isRequired,
hidden: PropTypes.bool,
...WithRouterPropTypes,
};
handleFollow = () => {
@ -48,11 +45,11 @@ class Header extends ImmutablePureComponent {
};
handleMention = () => {
this.props.onMention(this.props.account, this.props.history);
this.props.onMention(this.props.account);
};
handleDirect = () => {
this.props.onDirect(this.props.account, this.props.history);
this.props.onDirect(this.props.account);
};
handleReport = () => {
@ -158,4 +155,4 @@ class Header extends ImmutablePureComponent {
}
export default withRouter(Header);
export default Header;

View File

@ -75,12 +75,12 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}
},
onMention (account, router) {
dispatch(mentionCompose(account, router));
onMention (account) {
dispatch(mentionCompose(account));
},
onDirect (account, router) {
dispatch(directCompose(account, router));
onDirect (account) {
dispatch(directCompose(account));
},
onReblogToggle (account) {

View File

@ -10,8 +10,6 @@ import ImmutablePureComponent from 'react-immutable-pure-component';
import { length } from 'stringz';
import { WithOptionalRouterPropTypes, withOptionalRouter } from 'flavours/glitch/utils/react_router';
import AutosuggestInput from '../../../components/autosuggest_input';
import AutosuggestTextarea from '../../../components/autosuggest_textarea';
import { Button } from '../../../components/button';
@ -81,7 +79,6 @@ class ComposeForm extends ImmutablePureComponent {
singleColumn: PropTypes.bool,
lang: PropTypes.string,
maxChars: PropTypes.number,
...WithOptionalRouterPropTypes
};
static defaultProps = {
@ -141,9 +138,9 @@ class ComposeForm extends ImmutablePureComponent {
// Submit unless there are media with missing descriptions
if (this.props.mediaDescriptionConfirmation && this.props.media && this.props.media.some(item => !item.get('description'))) {
const firstWithoutDescription = this.props.media.find(item => !item.get('description'));
this.props.onMediaDescriptionConfirm(this.props.history || null, firstWithoutDescription.get('id'), overridePrivacy);
this.props.onMediaDescriptionConfirm(firstWithoutDescription.get('id'), overridePrivacy);
} else {
this.props.onSubmit(this.props.history || null, overridePrivacy);
this.props.onSubmit(overridePrivacy);
}
};
@ -351,4 +348,4 @@ class ComposeForm extends ImmutablePureComponent {
}
export default withOptionalRouter(injectIntl(ComposeForm));
export default injectIntl(ComposeForm);

View File

@ -82,8 +82,8 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
dispatch(changeCompose(text));
},
onSubmit (router, overridePrivacy = null) {
dispatch(submitCompose(router, overridePrivacy));
onSubmit (overridePrivacy = null) {
dispatch(submitCompose(overridePrivacy));
},
onClearSuggestions () {
@ -110,14 +110,14 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
dispatch(insertEmojiCompose(position, data, needsSpace));
},
onMediaDescriptionConfirm (routerHistory, mediaId, overridePrivacy = null) {
onMediaDescriptionConfirm (mediaId, overridePrivacy = null) {
dispatch(openModal({
modalType: 'CONFIRM',
modalProps: {
message: intl.formatMessage(messages.missingDescriptionMessage),
confirm: intl.formatMessage(messages.missingDescriptionConfirm),
onConfirm: () => {
dispatch(submitCompose(routerHistory, overridePrivacy));
dispatch(submitCompose(overridePrivacy));
},
secondary: intl.formatMessage(messages.missingDescriptionEdit),
onSecondary: () => dispatch(openModal({

View File

@ -126,14 +126,14 @@ export const Conversation = ({ conversation, scrollKey, onMoveUp, onMoveDown })
modalProps: {
message: intl.formatMessage(messages.replyMessage),
confirm: intl.formatMessage(messages.replyConfirm),
onConfirm: () => dispatch(replyCompose(lastStatus, history)),
onConfirm: () => dispatch(replyCompose(lastStatus)),
},
}));
} else {
dispatch(replyCompose(lastStatus, history));
dispatch(replyCompose(lastStatus));
}
});
}, [dispatch, lastStatus, history, intl]);
}, [dispatch, lastStatus, intl]);
const handleDelete = useCallback(() => {
dispatch(deleteConversation(id));

View File

@ -92,7 +92,7 @@ class Notification extends ImmutablePureComponent {
e.preventDefault();
const { notification, onMention } = this.props;
onMention(notification.get('account'), this.props.history);
onMention(notification.get('account'));
};
handleHotkeyFavourite = () => {

View File

@ -31,8 +31,8 @@ const makeMapStateToProps = () => {
};
const mapDispatchToProps = dispatch => ({
onMention: (account, router) => {
dispatch(mentionCompose(account, router));
onMention: (account) => {
dispatch(mentionCompose(account));
},
onModalReblog (status, privacy) {

View File

@ -3,7 +3,7 @@ import { useCallback } from 'react';
import { FormattedMessage, useIntl, defineMessages } from 'react-intl';
import { Helmet } from 'react-helmet';
import { Link, Switch, Route, useHistory } from 'react-router-dom';
import { Link, Switch, Route } from 'react-router-dom';
import { useDispatch } from 'react-redux';
@ -34,11 +34,10 @@ const Onboarding = () => {
const account = useAppSelector(state => state.getIn(['accounts', me]));
const dispatch = useDispatch();
const intl = useIntl();
const history = useHistory();
const handleComposeClick = useCallback(() => {
dispatch(focusCompose(history, intl.formatMessage(messages.template)));
}, [dispatch, intl, history]);
dispatch(focusCompose(intl.formatMessage(messages.template)));
}, [dispatch, intl]);
return (
<Column>

View File

@ -63,13 +63,13 @@ class Footer extends ImmutablePureComponent {
};
_performReply = () => {
const { dispatch, status, onClose, history } = this.props;
const { dispatch, status, onClose } = this.props;
if (onClose) {
onClose(true);
}
dispatch(replyCompose(status, history));
dispatch(replyCompose(status));
};
handleReplyClick = () => {

View File

@ -4,7 +4,6 @@ import { PureComponent } from 'react';
import { defineMessages, injectIntl } from 'react-intl';
import classNames from 'classnames';
import { withRouter } from 'react-router-dom';
import ImmutablePropTypes from 'react-immutable-proptypes';
@ -23,7 +22,6 @@ import RepeatPrivateActiveIcon from '@/svg-icons/repeat_private_active.svg?react
import { identityContextPropShape, withIdentity } from 'flavours/glitch/identity_context';
import { PERMISSION_MANAGE_USERS, PERMISSION_MANAGE_FEDERATION } from 'flavours/glitch/permissions';
import { accountAdminLink, statusAdminLink } from 'flavours/glitch/utils/backend_links';
import { WithRouterPropTypes } from 'flavours/glitch/utils/react_router';
import { IconButton } from '../../../components/icon_button';
import DropdownMenuContainer from '../../../containers/dropdown_menu_container';
@ -78,7 +76,6 @@ class ActionBar extends PureComponent {
onPin: PropTypes.func,
onEmbed: PropTypes.func,
intl: PropTypes.object.isRequired,
...WithRouterPropTypes,
};
handleReplyClick = () => {
@ -98,23 +95,23 @@ class ActionBar extends PureComponent {
};
handleDeleteClick = () => {
this.props.onDelete(this.props.status, this.props.history);
this.props.onDelete(this.props.status);
};
handleRedraftClick = () => {
this.props.onDelete(this.props.status, this.props.history, true);
this.props.onDelete(this.props.status, true);
};
handleEditClick = () => {
this.props.onEdit(this.props.status, this.props.history);
this.props.onEdit(this.props.status);
};
handleDirectClick = () => {
this.props.onDirect(this.props.status.get('account'), this.props.history);
this.props.onDirect(this.props.status.get('account'));
};
handleMentionClick = () => {
this.props.onMention(this.props.status.get('account'), this.props.history);
this.props.onMention(this.props.status.get('account'));
};
handleMuteClick = () => {
@ -262,4 +259,4 @@ class ActionBar extends PureComponent {
}
export default withRouter(withIdentity(injectIntl(ActionBar)));
export default withIdentity(injectIntl(ActionBar));

View File

@ -52,7 +52,7 @@ const makeMapStateToProps = () => {
const mapDispatchToProps = (dispatch, { intl }) => ({
onReply (status, router) {
onReply (status) {
dispatch((_, getState) => {
let state = getState();
if (state.getIn(['compose', 'text']).trim().length !== 0) {
@ -61,11 +61,11 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
modalProps: {
message: intl.formatMessage(messages.replyMessage),
confirm: intl.formatMessage(messages.replyConfirm),
onConfirm: () => dispatch(replyCompose(status, router)),
onConfirm: () => dispatch(replyCompose(status)),
},
}));
} else {
dispatch(replyCompose(status, router));
dispatch(replyCompose(status));
}
});
},
@ -112,27 +112,27 @@ const mapDispatchToProps = (dispatch, { intl }) => ({
}));
},
onDelete (status, history, withRedraft = false) {
onDelete (status, withRedraft = false) {
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
dispatch(deleteStatus(status.get('id'), withRedraft));
} else {
dispatch(openModal({
modalType: 'CONFIRM',
modalProps: {
message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
onConfirm: () => dispatch(deleteStatus(status.get('id'), withRedraft)),
},
}));
}
},
onDirect (account, router) {
dispatch(directCompose(account, router));
onDirect (account) {
dispatch(directCompose(account));
},
onMention (account, router) {
dispatch(mentionCompose(account, router));
onMention (account) {
dispatch(mentionCompose(account));
},
onOpenMedia (media, index, lang) {

View File

@ -324,11 +324,11 @@ class Status extends ImmutablePureComponent {
message: intl.formatMessage(messages.replyMessage),
confirm: intl.formatMessage(messages.replyConfirm),
onDoNotAsk: () => dispatch(changeLocalSetting(['confirm_before_clearing_draft'], false)),
onConfirm: () => dispatch(replyCompose(status, this.props.history)),
onConfirm: () => dispatch(replyCompose(status)),
},
}));
} else {
dispatch(replyCompose(status, this.props.history));
dispatch(replyCompose(status));
}
} else {
dispatch(openModal({
@ -384,33 +384,33 @@ class Status extends ImmutablePureComponent {
}
};
handleDeleteClick = (status, history, withRedraft = false) => {
handleDeleteClick = (status, withRedraft = false) => {
const { dispatch, intl } = this.props;
if (!deleteModal) {
dispatch(deleteStatus(status.get('id'), history, withRedraft));
dispatch(deleteStatus(status.get('id'), withRedraft));
} else {
dispatch(openModal({
modalType: 'CONFIRM',
modalProps: {
message: intl.formatMessage(withRedraft ? messages.redraftMessage : messages.deleteMessage),
confirm: intl.formatMessage(withRedraft ? messages.redraftConfirm : messages.deleteConfirm),
onConfirm: () => dispatch(deleteStatus(status.get('id'), history, withRedraft)),
onConfirm: () => dispatch(deleteStatus(status.get('id'), withRedraft)),
},
}));
}
};
handleEditClick = (status, history) => {
this.props.dispatch(editStatus(status.get('id'), history));
handleEditClick = (status) => {
this.props.dispatch(editStatus(status.get('id')));
};
handleDirectClick = (account, history) => {
this.props.dispatch(directCompose(account, history));
handleDirectClick = (account) => {
this.props.dispatch(directCompose(account));
};
handleMentionClick = (account, history) => {
this.props.dispatch(mentionCompose(account, history));
handleMentionClick = (account) => {
this.props.dispatch(mentionCompose(account));
};
handleOpenMedia = (media, index, lang) => {