Fix circular import between statuses/compose actions

This commit is contained in:
Alex Gleason 2024-10-19 18:20:43 -05:00
parent 76a4f6ad57
commit 6194cb8d1c
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
5 changed files with 47 additions and 43 deletions

View File

@ -0,0 +1,38 @@
import { AppDispatch, RootState } from 'soapbox/store';
import { getFeatures, parseVersion } from 'soapbox/utils/features';
import type { Status } from 'soapbox/types/entities';
export const COMPOSE_SET_STATUS = 'COMPOSE_SET_STATUS' as const;
export interface ComposeSetStatusAction {
type: typeof COMPOSE_SET_STATUS;
id: string;
status: Status;
rawText: string;
explicitAddressing: boolean;
spoilerText?: string;
contentType?: string | false;
v: ReturnType<typeof parseVersion>;
withRedraft?: boolean;
}
export const setComposeToStatus = (status: Status, rawText: string, spoilerText?: string, contentType?: string | false, withRedraft?: boolean) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const { instance } = getState();
const { explicitAddressing } = getFeatures(instance);
const action: ComposeSetStatusAction = {
type: COMPOSE_SET_STATUS,
id: 'compose-modal',
status,
rawText,
explicitAddressing,
spoilerText,
contentType,
v: parseVersion(instance.version),
withRedraft,
};
dispatch(action);
};

View File

@ -11,8 +11,9 @@ import { selectAccount, selectOwnAccount } from 'soapbox/selectors';
import { tagHistory } from 'soapbox/settings';
import toast from 'soapbox/toast';
import { isLoggedIn } from 'soapbox/utils/auth';
import { getFeatures, parseVersion } from 'soapbox/utils/features';
import { getFeatures } from 'soapbox/utils/features';
import { ComposeSetStatusAction } from './compose-status';
import { chooseEmoji } from './emojis';
import { importFetchedAccounts } from './importer';
import { uploadFile, updateMedia } from './media';
@ -85,8 +86,6 @@ const COMPOSE_SCHEDULE_REMOVE = 'COMPOSE_SCHEDULE_REMOVE' as const;
const COMPOSE_ADD_TO_MENTIONS = 'COMPOSE_ADD_TO_MENTIONS' as const;
const COMPOSE_REMOVE_FROM_MENTIONS = 'COMPOSE_REMOVE_FROM_MENTIONS' as const;
const COMPOSE_SET_STATUS = 'COMPOSE_SET_STATUS' as const;
const COMPOSE_EDITOR_STATE_SET = 'COMPOSE_EDITOR_STATE_SET' as const;
const COMPOSE_CHANGE_MEDIA_ORDER = 'COMPOSE_CHANGE_MEDIA_ORDER' as const;
@ -102,38 +101,6 @@ const messages = defineMessages({
replyMessage: { id: 'confirmations.reply.message', defaultMessage: 'Replying now will overwrite the message you are currently composing. Are you sure you want to proceed?' },
});
interface ComposeSetStatusAction {
type: typeof COMPOSE_SET_STATUS;
id: string;
status: Status;
rawText: string;
explicitAddressing: boolean;
spoilerText?: string;
contentType?: string | false;
v: ReturnType<typeof parseVersion>;
withRedraft?: boolean;
}
const setComposeToStatus = (status: Status, rawText: string, spoilerText?: string, contentType?: string | false, withRedraft?: boolean) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const { instance } = getState();
const { explicitAddressing } = getFeatures(instance);
const action: ComposeSetStatusAction = {
type: COMPOSE_SET_STATUS,
id: 'compose-modal',
status,
rawText,
explicitAddressing,
spoilerText,
contentType,
v: parseVersion(instance.version),
withRedraft,
};
dispatch(action);
};
const changeCompose = (composeId: string, text: string) => ({
type: COMPOSE_CHANGE,
id: composeId,
@ -952,11 +919,9 @@ export {
COMPOSE_SCHEDULE_REMOVE,
COMPOSE_ADD_TO_MENTIONS,
COMPOSE_REMOVE_FROM_MENTIONS,
COMPOSE_SET_STATUS,
COMPOSE_EDITOR_STATE_SET,
COMPOSE_SET_GROUP_TIMELINE_VISIBLE,
COMPOSE_CHANGE_MEDIA_ORDER,
setComposeToStatus,
changeCompose,
replyCompose,
cancelReplyCompose,

View File

@ -4,7 +4,7 @@ import { shouldHaveCard } from 'soapbox/utils/status';
import api, { getNextLink } from '../api';
import { setComposeToStatus } from './compose';
import { setComposeToStatus } from './compose-status';
import { fetchGroupRelationships } from './groups';
import { importFetchedStatus, importFetchedStatuses } from './importer';
import { openModal } from './modals';

View File

@ -1,6 +1,7 @@
import { List as ImmutableList, Record as ImmutableRecord, fromJS } from 'immutable';
import * as actions from 'soapbox/actions/compose';
import { COMPOSE_SET_STATUS } from 'soapbox/actions/compose-status';
import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS } from 'soapbox/actions/me';
import { SETTING_CHANGE } from 'soapbox/actions/settings';
import { TIMELINE_DELETE } from 'soapbox/actions/timelines';
@ -43,7 +44,7 @@ describe('compose reducer', () => {
const status = await import('soapbox/__fixtures__/pleroma-status-deleted.json');
const action = {
type: actions.COMPOSE_SET_STATUS,
type: COMPOSE_SET_STATUS,
id: 'compose-modal',
status: normalizeStatus(fromJS(status)),
v: { software: 'Pleroma' },
@ -58,7 +59,7 @@ describe('compose reducer', () => {
const status = await import('soapbox/__fixtures__/pleroma-status-deleted.json');
const action = {
type: actions.COMPOSE_SET_STATUS,
type: COMPOSE_SET_STATUS,
id: 'compose-modal',
status: normalizeStatus(fromJS(status)),
};
@ -73,7 +74,7 @@ describe('compose reducer', () => {
const action = {
id: 'compose-modal',
withRedraft: false,
type: actions.COMPOSE_SET_STATUS,
type: COMPOSE_SET_STATUS,
status: normalizeStatus(fromJS(status)),
};
@ -87,7 +88,7 @@ describe('compose reducer', () => {
const action = {
id: 'compose-modal',
withRedraft: true,
type: actions.COMPOSE_SET_STATUS,
type: COMPOSE_SET_STATUS,
status: normalizeStatus(fromJS(status)),
};

View File

@ -48,13 +48,13 @@ import {
COMPOSE_POLL_SETTINGS_CHANGE,
COMPOSE_ADD_TO_MENTIONS,
COMPOSE_REMOVE_FROM_MENTIONS,
COMPOSE_SET_STATUS,
COMPOSE_EVENT_REPLY,
COMPOSE_EDITOR_STATE_SET,
COMPOSE_SET_GROUP_TIMELINE_VISIBLE,
ComposeAction,
COMPOSE_CHANGE_MEDIA_ORDER,
} from '../actions/compose';
import { COMPOSE_SET_STATUS } from '../actions/compose-status';
import { EVENT_COMPOSE_CANCEL, EVENT_FORM_SET, type EventsAction } from '../actions/events';
import { ME_FETCH_SUCCESS, ME_PATCH_SUCCESS, MeAction } from '../actions/me';
import { SETTING_CHANGE, FE_NAME, SettingsAction } from '../actions/settings';