Refactor: replace Immutable.js methods with plain JavaScript equivalents - "action/compose"

remove-immutable-compose
danidfra 2024-12-18 17:20:41 -03:00
rodzic ed629e69fa
commit 2127bd52ce
1 zmienionych plików z 12 dodań i 12 usunięć

Wyświetl plik

@ -1,5 +1,4 @@
import { throttle } from 'es-toolkit';
import { List as ImmutableList } from 'immutable';
import { defineMessages, IntlShape } from 'react-intl';
import { HTTPError } from 'soapbox/api/HTTPError.ts';
@ -249,16 +248,16 @@ const handleComposeSubmit = (dispatch: AppDispatch, getState: () => RootState, c
};
const needsDescriptions = (state: RootState, composeId: string) => {
const media = state.compose.get(composeId)!.media_attachments;
const media = state.compose[composeId].media_attachments;
const missingDescriptionModal = getSettings(state).get('missingDescriptionModal');
const hasMissing = media.filter(item => !item.description).size > 0;
const hasMissing = media.filter(item => !item.description).length > 0;
return missingDescriptionModal && hasMissing;
};
const validateSchedule = (state: RootState, composeId: string) => {
const schedule = state.compose.get(composeId)?.schedule;
const schedule = state.compose[composeId]?.schedule;
if (!schedule) return true;
const fiveMinutesFromNow = new Date(new Date().getTime() + 300000);
@ -278,7 +277,7 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) =>
if (!isLoggedIn(getState)) return;
const state = getState();
const compose = state.compose.get(composeId)!;
const compose = state.compose[composeId];
const status = compose.text;
const media = compose.media_attachments;
@ -290,7 +289,7 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) =>
return;
}
if ((!status || !status.length) && media.size === 0) {
if ((!status || !status.length) && media.length === 0) {
return;
}
@ -307,7 +306,8 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) =>
const mentions: string[] | null = status.match(/(?:^|\s)@([^@\s]+(?:@[^@\s]+)?)/gi);
if (mentions) {
to = to.union(mentions.map(mention => mention.trim().slice(1)));
const trimmedMentions = mentions.map(mention => mention.trim().slice(1));
to = new Set([...to, ...trimmedMentions]);
}
dispatch(submitComposeRequest(composeId));
@ -366,9 +366,9 @@ const uploadCompose = (composeId: string, files: FileList, intl: IntlShape) =>
if (!isLoggedIn(getState)) return;
const attachmentLimit = getState().instance.configuration.statuses.max_media_attachments;
const media = getState().compose.get(composeId)?.media_attachments;
const media = getState().compose[composeId]?.media_attachments;
const progress: number[] = new Array(files.length).fill(0);
const mediaCount = media ? media.size : 0;
const mediaCount = media ? media.length : 0;
if (files.length + mediaCount > attachmentLimit) {
toast.error(messages.uploadErrorLimit);
@ -614,7 +614,7 @@ const selectComposeSuggestion = (composeId: string, position: number, token: str
dispatch(action);
};
const updateSuggestionTags = (composeId: string, token: string, tags: ImmutableList<Tag>) => ({
const updateSuggestionTags = (composeId: string, token: string, tags: Tag[]) => ({
type: COMPOSE_SUGGESTION_TAGS_UPDATE,
id: composeId,
token,
@ -630,14 +630,14 @@ const updateTagHistory = (composeId: string, tags: string[]) => ({
const insertIntoTagHistory = (composeId: string, recognizedTags: APIEntity[], text: string) =>
(dispatch: AppDispatch, getState: () => RootState) => {
const state = getState();
const oldHistory = state.compose.get(composeId)!.tagHistory;
const oldHistory = state.compose[composeId]!.tagHistory;
const me = state.me;
const names = recognizedTags
.filter(tag => text.match(new RegExp(`#${tag.name}`, 'i')))
.map(tag => tag.name);
const intersectedOldHistory = oldHistory.filter(name => names.findIndex(newName => newName.toLowerCase() === name.toLowerCase()) === -1);
names.push(...intersectedOldHistory.toJS());
names.push(...intersectedOldHistory);
const newHistory = names.slice(0, 1000);