From 30d4303345a6a24c0e85579f9e9cefbc38109c50 Mon Sep 17 00:00:00 2001 From: Claire Date: Mon, 25 Aug 2025 14:25:35 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20Edit=20as=20well=20as=20=E2=80=9CDelete?= =?UTF-8?q?=20&=20Redraft=E2=80=9D=20on=20a=20poll=20not=20inserting=20emp?= =?UTF-8?q?ty=20option=20(#35892)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/javascript/mastodon/actions/compose.js | 15 ++++++++++----- app/javascript/mastodon/actions/statuses.js | 13 +++++++++---- app/javascript/mastodon/reducers/compose.js | 14 ++++++++++++-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js index 6abfd6157..6d05ef654 100644 --- a/app/javascript/mastodon/actions/compose.js +++ b/app/javascript/mastodon/actions/compose.js @@ -94,11 +94,16 @@ export const ensureComposeIsVisible = (getState, routerHistory) => { }; export function setComposeToStatus(status, text, spoiler_text) { - return{ - type: COMPOSE_SET_STATUS, - status, - text, - spoiler_text, + return (dispatch, getState) => { + const maxOptions = getState().server.getIn(['server', 'configuration', 'polls', 'max_options']); + + dispatch({ + type: COMPOSE_SET_STATUS, + status, + text, + spoiler_text, + maxOptions, + }); }; } diff --git a/app/javascript/mastodon/actions/statuses.js b/app/javascript/mastodon/actions/statuses.js index 3aed80735..5809f1497 100644 --- a/app/javascript/mastodon/actions/statuses.js +++ b/app/javascript/mastodon/actions/statuses.js @@ -86,10 +86,15 @@ export function fetchStatusFail(id, error, skipLoading) { } export function redraft(status, raw_text) { - return { - type: REDRAFT, - status, - raw_text, + return (dispatch, getState) => { + const maxOptions = getState().server.getIn(['server', 'configuration', 'polls', 'max_options']); + + dispatch({ + type: REDRAFT, + status, + raw_text, + maxOptions, + }); }; } diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index ad367ea7b..b5fc29af9 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -492,8 +492,13 @@ export default function compose(state = initialState, action) { } if (action.status.get('poll')) { + let options = ImmutableList(action.status.get('poll').options.map(x => x.title)); + if (options.size < action.maxOptions) { + options = options.push(''); + } + map.set('poll', ImmutableMap({ - options: action.status.getIn(['poll', 'options']).map(x => x.get('title')), + options: options, multiple: action.status.getIn(['poll', 'multiple']), expires_in: expiresInFromExpiresAt(action.status.getIn(['poll', 'expires_at'])), })); @@ -521,8 +526,13 @@ export default function compose(state = initialState, action) { } if (action.status.get('poll')) { + let options = ImmutableList(action.status.get('poll').options.map(x => x.title)); + if (options.size < action.maxOptions) { + options = options.push(''); + } + map.set('poll', ImmutableMap({ - options: action.status.getIn(['poll', 'options']).map(x => x.get('title')), + options: options, multiple: action.status.getIn(['poll', 'multiple']), expires_in: expiresInFromExpiresAt(action.status.getIn(['poll', 'expires_at'])), }));