From 64406519769684e5a6aa9d188708af16a78b5a19 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Mon, 11 Mar 2024 10:13:35 +0100 Subject: [PATCH] [Glitch] Use the server setting to get the max number of poll options in UI Port b9722dfe2bdb024e5e98b96d2fc5712d6cb5f747 to glitch-soc Signed-off-by: Claire --- app/javascript/flavours/glitch/actions/compose.js | 3 ++- .../glitch/features/compose/components/poll_form.jsx | 5 +++-- app/javascript/flavours/glitch/reducers/compose.js | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 9e65df7b39..2646aa7b02 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -822,11 +822,12 @@ export function addPollOption(title) { }; } -export function changePollOption(index, title) { +export function changePollOption(index, title, maxOptions) { return { type: COMPOSE_POLL_OPTION_CHANGE, index, title, + maxOptions, }; } diff --git a/app/javascript/flavours/glitch/features/compose/components/poll_form.jsx b/app/javascript/flavours/glitch/features/compose/components/poll_form.jsx index e757b9162a..361522d7b4 100644 --- a/app/javascript/flavours/glitch/features/compose/components/poll_form.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/poll_form.jsx @@ -59,10 +59,11 @@ const Option = ({ multipleChoice, index, title, autoFocus }) => { const dispatch = useDispatch(); const suggestions = useSelector(state => state.getIn(['compose', 'suggestions'])); const lang = useSelector(state => state.getIn(['compose', 'language'])); + const maxOptions = useSelector(state => state.getIn(['server', 'server', 'configuration', 'polls', 'max_options'])); const handleChange = useCallback(({ target: { value } }) => { - dispatch(changePollOption(index, value)); - }, [dispatch, index]); + dispatch(changePollOption(index, value, maxOptions)); + }, [dispatch, index, maxOptions]); const handleSuggestionsFetchRequested = useCallback(token => { dispatch(fetchComposeSuggestions(token)); diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js index 787e7ee2db..f96d9e959f 100644 --- a/app/javascript/flavours/glitch/reducers/compose.js +++ b/app/javascript/flavours/glitch/reducers/compose.js @@ -54,7 +54,7 @@ import { import { REDRAFT } from '../actions/statuses'; import { STORE_HYDRATE } from '../actions/store'; import { TIMELINE_DELETE } from '../actions/timelines'; -import { me, defaultContentType, pollLimits } from '../initial_state'; +import { me, defaultContentType } from '../initial_state'; import { recoverHashtags } from '../utils/hashtag'; import { unescapeHTML } from '../utils/html'; import { overwrite } from '../utils/js_helpers'; @@ -356,12 +356,12 @@ const updateSuggestionTags = (state, token) => { }); }; -const updatePoll = (state, index, value) => state.updateIn(['poll', 'options'], options => { +const updatePoll = (state, index, value, maxOptions) => state.updateIn(['poll', 'options'], options => { const tmp = options.set(index, value).filterNot(x => x.trim().length === 0); if (tmp.size === 0) { return tmp.push('').push(''); - } else if (tmp.size < pollLimits.max_options) { + } else if (tmp.size < maxOptions) { return tmp.push(''); } @@ -649,7 +649,7 @@ export default function compose(state = initialState, action) { case COMPOSE_POLL_REMOVE: return state.set('poll', null); case COMPOSE_POLL_OPTION_CHANGE: - return updatePoll(state, action.index, action.title); + return updatePoll(state, action.index, action.title, action.maxOptions); case COMPOSE_POLL_SETTINGS_CHANGE: return state.update('poll', poll => poll.set('expires_in', action.expiresIn).set('multiple', action.isMultiple)); case COMPOSE_LANGUAGE_CHANGE: