diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index e850a83a85..06c8ed5186 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -102,12 +102,17 @@ export const ensureComposeIsVisible = (getState) => { }; export function setComposeToStatus(status, text, spoiler_text, content_type) { - return{ - type: COMPOSE_SET_STATUS, - status, - text, - spoiler_text, - content_type, + return (dispatch, getState) => { + const maxOptions = getState().server.getIn(['server', 'configuration', 'polls', 'max_options']); + + dispatch({ + type: COMPOSE_SET_STATUS, + status, + text, + spoiler_text, + content_type, + maxOptions + }); }; } diff --git a/app/javascript/flavours/glitch/actions/statuses.js b/app/javascript/flavours/glitch/actions/statuses.js index 2b6b589b37..e852b54855 100644 --- a/app/javascript/flavours/glitch/actions/statuses.js +++ b/app/javascript/flavours/glitch/actions/statuses.js @@ -90,11 +90,16 @@ export function fetchStatusFail(id, error, skipLoading) { } export function redraft(status, raw_text, content_type) { - return { - type: REDRAFT, - status, - raw_text, - content_type, + return (dispatch, getState) => { + const maxOptions = getState().server.getIn(['server', 'configuration', 'polls', 'max_options']); + + dispatch({ + type: REDRAFT, + status, + raw_text, + content_type, + maxOptions, + }); }; } diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js index 04a2857836..d32dc604da 100644 --- a/app/javascript/flavours/glitch/reducers/compose.js +++ b/app/javascript/flavours/glitch/reducers/compose.js @@ -623,8 +623,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'])), })); @@ -653,8 +658,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'])), }));