pl-fe: compose reducer cleanup

Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
nicole mikołajczyk
2025-10-28 19:39:26 +01:00
parent 3f72d0dba5
commit 355b834c99
3 changed files with 47 additions and 43 deletions

View File

@ -139,8 +139,7 @@ const ComposeForm = <ID extends string>({ id, shouldCondense, autoFocus, clickab
spoiler_text: spoilerText, spoiler_text: spoilerText,
privacy, privacy,
is_submitting: isSubmitting, is_submitting: isSubmitting,
is_changing_upload: is_changing_upload: isChangingUpload,
isChangingUpload,
is_uploading: isUploading, is_uploading: isUploading,
schedule: scheduledAt, schedule: scheduledAt,
group_id: groupId, group_id: groupId,

View File

@ -18,10 +18,8 @@ describe('compose reducer', () => {
spoiler_text: '', spoiler_text: '',
privacy: 'public', privacy: 'public',
text: '', text: '',
focusDate: null,
caretPosition: null, caretPosition: null,
in_reply_to: null, in_reply_to: null,
is_composing: false,
is_submitting: false, is_submitting: false,
is_changing_upload: false, is_changing_upload: false,
is_uploading: false, is_uploading: false,

View File

@ -103,49 +103,64 @@ interface ClearLinkSuggestion {
} }
interface Compose { interface Compose {
caretPosition: number | null; // User-edited text
content_type: string;
draft_id: string | null;
editorState: string | null; editorState: string | null;
editorStateMap: Record<Language | string, string | null>; editorStateMap: Record<Language | string, string | null>;
focusDate: Date | null;
group_id: string | null;
idempotencyKey: string;
id: string | null;
in_reply_to: string | null;
is_changing_upload: boolean;
is_composing: boolean;
is_submitting: boolean;
is_uploading: boolean;
media_attachments: Array<MediaAttachment>;
poll: ComposePoll | null;
privacy: string;
progress: number;
quote: string | null;
resetFileKey: number | null;
schedule: Date | null;
sensitive: boolean;
spoiler_text: string; spoiler_text: string;
spoilerTextMap: Record<Language | string, string>; spoilerTextMap: Record<Language | string, string>;
text: string;
textMap: Record<Language | string, string>;
// Non-text content
poll: ComposePoll | null;
media_attachments: Array<MediaAttachment>;
// Post settings
content_type: string;
privacy: string;
federated: boolean;
language: Language | string | null;
sensitive: boolean;
interactionPolicy: InteractionPolicy | null;
schedule: Date | null;
// References to other posts/groups/users
draft_id: string | null;
group_id: string | null;
id: string | null;
in_reply_to: string | null;
quote: string | null;
to: Array<string>;
parent_reblogged_by: string | null;
// State flags
is_changing_upload: boolean;
is_submitting: boolean;
is_uploading: boolean;
progress: number;
// Internal
caretPosition: number | null;
idempotencyKey: string;
resetFileKey: number | null;
// Currently modified language
modified_language: Language | string | null;
// Suggestions
approvalRequired: boolean;
suggested_language: string | null;
suggestions: Array<string> | Array<Emoji>; suggestions: Array<string> | Array<Emoji>;
suggestion_token: string | null; suggestion_token: string | null;
tagHistory: Array<string>; tagHistory: Array<string>;
text: string;
textMap: Record<Language | string, string>;
to: Array<string>;
parent_reblogged_by: string | null;
dismissed_quotes: Array<string>;
language: Language | string | null;
modified_language: Language | string | null;
suggested_language: string | null;
federated: boolean;
approvalRequired: boolean;
interactionPolicy: InteractionPolicy | null;
dismissed_clear_links_suggestions: Array<string>; dismissed_clear_links_suggestions: Array<string>;
clear_link_suggestion: ClearLinkSuggestion | null; clear_link_suggestion: ClearLinkSuggestion | null;
preview: Partial<BaseStatus> | null; preview: Partial<BaseStatus> | null;
dismissed_quotes: Array<string>;
hashtag_casing_suggestion: string | null; hashtag_casing_suggestion: string | null;
hashtag_casing_suggestion_ignored: boolean | null; hashtag_casing_suggestion_ignored: boolean | null;
// Moderation features
redacting: boolean; redacting: boolean;
redactingOverwrite: boolean; redactingOverwrite: boolean;
} }
@ -156,13 +171,11 @@ const newCompose = (params: Partial<Compose> = {}): Compose => ({
draft_id: null, draft_id: null,
editorState: null, editorState: null,
editorStateMap: {}, editorStateMap: {},
focusDate: null,
group_id: null, group_id: null,
idempotencyKey: '', idempotencyKey: '',
id: null, id: null,
in_reply_to: null, in_reply_to: null,
is_changing_upload: false, is_changing_upload: false,
is_composing: false,
is_submitting: false, is_submitting: false,
is_uploading: false, is_uploading: false,
media_attachments: [], media_attachments: [],
@ -406,7 +419,6 @@ const compose = (state = initialState, action: ComposeAction | EventsAction | In
compose.text = !action.explicitAddressing ? statusToTextMentions(action.status, action.account) : ''; compose.text = !action.explicitAddressing ? statusToTextMentions(action.status, action.account) : '';
compose.privacy = privacyPreference(action.status.visibility, defaultCompose.privacy, action.status.list_id, action.conversationScope); compose.privacy = privacyPreference(action.status.visibility, defaultCompose.privacy, action.status.list_id, action.conversationScope);
compose.federated = action.status.local_only !== true; compose.federated = action.status.local_only !== true;
compose.focusDate = new Date();
compose.caretPosition = null; compose.caretPosition = null;
compose.idempotencyKey = crypto.randomUUID(); compose.idempotencyKey = crypto.randomUUID();
compose.content_type = defaultCompose.content_type; compose.content_type = defaultCompose.content_type;
@ -432,7 +444,6 @@ const compose = (state = initialState, action: ComposeAction | EventsAction | In
compose.parent_reblogged_by = null; compose.parent_reblogged_by = null;
compose.text = ''; compose.text = '';
compose.privacy = privacyPreference(action.status.visibility, defaultCompose.privacy, action.status.list_id); compose.privacy = privacyPreference(action.status.visibility, defaultCompose.privacy, action.status.list_id);
compose.focusDate = new Date();
compose.caretPosition = null; compose.caretPosition = null;
compose.idempotencyKey = crypto.randomUUID(); compose.idempotencyKey = crypto.randomUUID();
compose.content_type = defaultCompose.content_type; compose.content_type = defaultCompose.content_type;
@ -492,7 +503,6 @@ const compose = (state = initialState, action: ComposeAction | EventsAction | In
case COMPOSE_MENTION: case COMPOSE_MENTION:
return updateCompose(state, 'compose-modal', compose => { return updateCompose(state, 'compose-modal', compose => {
compose.text = [compose.text.trim(), `@${action.account.acct} `].filter((str) => str.length !== 0).join(' '); compose.text = [compose.text.trim(), `@${action.account.acct} `].filter((str) => str.length !== 0).join(' ');
compose.focusDate = new Date();
compose.caretPosition = null; compose.caretPosition = null;
compose.idempotencyKey = crypto.randomUUID(); compose.idempotencyKey = crypto.randomUUID();
}); });
@ -500,7 +510,6 @@ const compose = (state = initialState, action: ComposeAction | EventsAction | In
return updateCompose(state, 'compose-modal', compose => { return updateCompose(state, 'compose-modal', compose => {
compose.text = [compose.text.trim(), `@${action.account.acct} `].filter((str) => str.length !== 0).join(' '); compose.text = [compose.text.trim(), `@${action.account.acct} `].filter((str) => str.length !== 0).join(' ');
compose.privacy = 'direct'; compose.privacy = 'direct';
compose.focusDate = new Date();
compose.caretPosition = null; compose.caretPosition = null;
compose.idempotencyKey = crypto.randomUUID(); compose.idempotencyKey = crypto.randomUUID();
}); });
@ -508,7 +517,6 @@ const compose = (state = initialState, action: ComposeAction | EventsAction | In
return updateCompose(state, action.composeId, compose => { return updateCompose(state, action.composeId, compose => {
compose.privacy = 'group'; compose.privacy = 'group';
compose.group_id = action.groupId; compose.group_id = action.groupId;
compose.focusDate = new Date();
compose.caretPosition = null; compose.caretPosition = null;
compose.idempotencyKey = crypto.randomUUID(); compose.idempotencyKey = crypto.randomUUID();
}); });
@ -561,7 +569,6 @@ const compose = (state = initialState, action: ComposeAction | EventsAction | In
compose.parent_reblogged_by = null; compose.parent_reblogged_by = null;
compose.in_reply_to = action.status.in_reply_to_id; compose.in_reply_to = action.status.in_reply_to_id;
compose.privacy = action.status.visibility; compose.privacy = action.status.visibility;
compose.focusDate = new Date();
compose.caretPosition = null; compose.caretPosition = null;
compose.idempotencyKey = crypto.randomUUID(); compose.idempotencyKey = crypto.randomUUID();
const contentType = action.contentType === 'text/markdown' && state.default.content_type === 'wysiwyg' const contentType = action.contentType === 'text/markdown' && state.default.content_type === 'wysiwyg'