Merge remote-tracking branch 'parent/main' into upstream-20250403
This commit is contained in:
commit
32f5604499
265 changed files with 6227 additions and 3383 deletions
|
@ -147,6 +147,7 @@ function clearAll(state) {
|
|||
map.set('sensitive', state.get('default_sensitive'));
|
||||
map.set('language', state.get('default_language'));
|
||||
map.update('media_attachments', list => list.clear());
|
||||
map.set('progress', 0);
|
||||
map.set('poll', null);
|
||||
map.set('idempotencyKey', uuid());
|
||||
normalizePrivacy(map);
|
||||
|
@ -163,6 +164,7 @@ function appendMedia(state, media, file) {
|
|||
map.update('media_attachments', list => list.push(media.set('unattached', true)));
|
||||
map.set('is_uploading', false);
|
||||
map.set('is_processing', false);
|
||||
map.set('progress', 0);
|
||||
map.set('resetFileKey', Math.floor((Math.random() * 0x10000)));
|
||||
map.set('idempotencyKey', uuid());
|
||||
map.update('pending_media_attachments', n => n - 1);
|
||||
|
@ -396,6 +398,8 @@ const updatePoll = (state, index, value, maxOptions) => state.updateIn(['poll',
|
|||
return tmp;
|
||||
});
|
||||
|
||||
const calculateProgress = (loaded, total) => Math.min(Math.round((loaded / total) * 100), 100);
|
||||
|
||||
/** @type {import('@reduxjs/toolkit').Reducer<typeof initialState>} */
|
||||
export const composeReducer = (state = initialState, action) => {
|
||||
if (changeUploadCompose.fulfilled.match(action)) {
|
||||
|
@ -520,15 +524,19 @@ export const composeReducer = (state = initialState, action) => {
|
|||
case COMPOSE_UPLOAD_SUCCESS:
|
||||
return appendMedia(state, fromJS(action.media), action.file);
|
||||
case COMPOSE_UPLOAD_FAIL:
|
||||
return state.set('is_uploading', false).set('is_processing', false).update('pending_media_attachments', n => n - 1);
|
||||
return state
|
||||
.set('is_uploading', false)
|
||||
.set('is_processing', false)
|
||||
.set('progress', 0)
|
||||
.update('pending_media_attachments', n => n - 1);
|
||||
case COMPOSE_UPLOAD_UNDO:
|
||||
return removeMedia(state, action.media_id);
|
||||
case COMPOSE_UPLOAD_PROGRESS:
|
||||
return state.set('progress', Math.round((action.loaded / action.total) * 100));
|
||||
return state.set('progress', calculateProgress(action.loaded, action.total));
|
||||
case THUMBNAIL_UPLOAD_REQUEST:
|
||||
return state.set('isUploadingThumbnail', true);
|
||||
case THUMBNAIL_UPLOAD_PROGRESS:
|
||||
return state.set('thumbnailProgress', Math.round((action.loaded / action.total) * 100));
|
||||
return state.set('thumbnailProgress', calculateProgress(action.loaded, action.total));
|
||||
case THUMBNAIL_UPLOAD_FAIL:
|
||||
return state.set('isUploadingThumbnail', false);
|
||||
case THUMBNAIL_UPLOAD_SUCCESS:
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
import { Map as ImmutableMap, OrderedSet as ImmutableOrderedSet } from 'immutable';
|
||||
|
||||
import {
|
||||
DOMAIN_BLOCKS_FETCH_SUCCESS,
|
||||
DOMAIN_BLOCKS_EXPAND_SUCCESS,
|
||||
unblockDomainSuccess
|
||||
} from '../actions/domain_blocks';
|
||||
|
||||
const initialState = ImmutableMap({
|
||||
blocks: ImmutableMap({
|
||||
items: ImmutableOrderedSet(),
|
||||
}),
|
||||
});
|
||||
|
||||
export default function domainLists(state = initialState, action) {
|
||||
switch(action.type) {
|
||||
case DOMAIN_BLOCKS_FETCH_SUCCESS:
|
||||
return state.setIn(['blocks', 'items'], ImmutableOrderedSet(action.domains)).setIn(['blocks', 'next'], action.next);
|
||||
case DOMAIN_BLOCKS_EXPAND_SUCCESS:
|
||||
return state.updateIn(['blocks', 'items'], set => set.union(action.domains)).setIn(['blocks', 'next'], action.next);
|
||||
case unblockDomainSuccess.type:
|
||||
return state.updateIn(['blocks', 'items'], set => set.delete(action.payload.domain));
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ import { composeReducer } from './compose';
|
|||
import contexts from './contexts';
|
||||
import conversations from './conversations';
|
||||
import custom_emojis from './custom_emojis';
|
||||
import domain_lists from './domain_lists';
|
||||
import { dropdownMenuReducer } from './dropdown_menu';
|
||||
import filters from './filters';
|
||||
import followed_tags from './followed_tags';
|
||||
|
@ -53,7 +52,6 @@ const reducers = {
|
|||
loadingBar: loadingBarReducer,
|
||||
modal: modalReducer,
|
||||
user_lists,
|
||||
domain_lists,
|
||||
status_lists,
|
||||
accounts: accountsReducer,
|
||||
accounts_map,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import type { Reducer } from '@reduxjs/toolkit';
|
||||
import { Map as ImmutableMap } from 'immutable';
|
||||
|
||||
import { importPolls } from 'mastodon/actions/importer/polls';
|
||||
import { makeEmojiMap } from 'mastodon/models/custom_emoji';
|
||||
|
@ -11,57 +10,48 @@ import {
|
|||
STATUS_TRANSLATE_UNDO,
|
||||
} from '../actions/statuses';
|
||||
|
||||
const initialState = ImmutableMap<string, Poll>();
|
||||
const initialState: Record<string, Poll> = {};
|
||||
type PollsState = typeof initialState;
|
||||
|
||||
const statusTranslateSuccess = (
|
||||
state: PollsState,
|
||||
pollTranslation: Poll | undefined,
|
||||
) => {
|
||||
if (!pollTranslation) return state;
|
||||
const statusTranslateSuccess = (state: PollsState, pollTranslation?: Poll) => {
|
||||
if (!pollTranslation) return;
|
||||
|
||||
return state.withMutations((map) => {
|
||||
const poll = state.get(pollTranslation.id);
|
||||
const poll = state[pollTranslation.id];
|
||||
|
||||
if (!poll) return;
|
||||
if (!poll) return;
|
||||
|
||||
const emojiMap = makeEmojiMap(poll.emojis);
|
||||
const emojiMap = makeEmojiMap(poll.emojis);
|
||||
|
||||
pollTranslation.options.forEach((item, index) => {
|
||||
map.setIn(
|
||||
[pollTranslation.id, 'options', index, 'translation'],
|
||||
createPollOptionTranslationFromServerJSON(item, emojiMap),
|
||||
);
|
||||
});
|
||||
pollTranslation.options.forEach((item, index) => {
|
||||
const option = poll.options[index];
|
||||
if (!option) return;
|
||||
|
||||
option.translation = createPollOptionTranslationFromServerJSON(
|
||||
item,
|
||||
emojiMap,
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const statusTranslateUndo = (state: PollsState, id: string) => {
|
||||
return state.withMutations((map) => {
|
||||
const options = map.get(id)?.options;
|
||||
|
||||
if (options) {
|
||||
options.forEach((item, index) =>
|
||||
map.deleteIn([id, 'options', index, 'translation']),
|
||||
);
|
||||
}
|
||||
state[id]?.options.forEach((option) => {
|
||||
option.translation = null;
|
||||
});
|
||||
};
|
||||
|
||||
export const pollsReducer: Reducer<PollsState> = (
|
||||
state = initialState,
|
||||
draft = initialState,
|
||||
action,
|
||||
) => {
|
||||
if (importPolls.match(action)) {
|
||||
return state.withMutations((polls) => {
|
||||
action.payload.polls.forEach((poll) => polls.set(poll.id, poll));
|
||||
action.payload.polls.forEach((poll) => {
|
||||
draft[poll.id] = poll;
|
||||
});
|
||||
} else if (action.type === STATUS_TRANSLATE_SUCCESS)
|
||||
return statusTranslateSuccess(
|
||||
state,
|
||||
(action.translation as { poll?: Poll }).poll,
|
||||
);
|
||||
else if (action.type === STATUS_TRANSLATE_UNDO)
|
||||
return statusTranslateUndo(state, action.pollId as string);
|
||||
else return state;
|
||||
statusTranslateSuccess(draft, (action.translation as { poll?: Poll }).poll);
|
||||
else if (action.type === STATUS_TRANSLATE_UNDO) {
|
||||
statusTranslateUndo(draft, action.pollId as string);
|
||||
}
|
||||
|
||||
return draft;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue