Update actions/compose

update-compose
danidfra 2024-12-09 11:51:08 -03:00
rodzic c44fc2cece
commit fe9f29e5f4
1 zmienionych plików z 11 dodań i 12 usunięć

Wyświetl plik

@ -1,6 +1,5 @@
import axios, { Canceler } from 'axios';
import { throttle } from 'es-toolkit';
import { List as ImmutableList } from 'immutable';
import { defineMessages, IntlShape } from 'react-intl';
import api from 'soapbox/api/index.ts';
@ -251,16 +250,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);
@ -280,7 +279,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;
@ -292,7 +291,7 @@ const submitCompose = (composeId: string, opts: SubmitComposeOpts = {}) =>
return;
}
if ((!status || !status.length) && media.size === 0) {
if ((!status || !status.length) && media.length === 0) {
return;
}
@ -309,7 +308,7 @@ 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)));
to = [...to, ...mentions.map(mention => mention.trim().slice(1))];
}
dispatch(submitComposeRequest(composeId));
@ -368,11 +367,11 @@ 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 = new Array(files.length).fill(0);
let total = Array.from(files).reduce((a, v) => a + v.size, 0);
const mediaCount = media ? media.size : 0;
const mediaCount = media ? media.length : 0;
if (files.length + mediaCount > attachmentLimit) {
toast.error(messages.uploadErrorLimit);
@ -627,7 +626,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,
@ -643,14 +642,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);