From 4c24022984f8b1862b9d19a57ab269894599f4d7 Mon Sep 17 00:00:00 2001 From: Jeremy Kescher Date: Sat, 24 Feb 2024 18:17:27 +0100 Subject: [PATCH] Fix min_options, let vanilla flavor behave properly for pollLimits --- app/javascript/flavours/glitch/reducers/compose.js | 7 +++++-- app/javascript/mastodon/initial_state.js | 4 +--- app/javascript/mastodon/reducers/compose.js | 13 ++++++++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/app/javascript/flavours/glitch/reducers/compose.js b/app/javascript/flavours/glitch/reducers/compose.js index 15bf1a1690..b291eaefc6 100644 --- a/app/javascript/flavours/glitch/reducers/compose.js +++ b/app/javascript/flavours/glitch/reducers/compose.js @@ -357,10 +357,13 @@ const updateSuggestionTags = (state, token) => { }; const updatePoll = (state, index, value) => state.updateIn(['poll', 'options'], options => { - const tmp = options.set(index, value).filterNot(x => x.trim().length === 0); + let tmp = options.set(index, value).filterNot(x => x.trim().length === 0); if (tmp.size === 0) { - return tmp.push('').push(''); + const minOptions = pollLimits.min_options ?? 2; + for (let i = 0; i < minOptions; i++) { + tmp = tmp.push(''); + } } else if (tmp.size < pollLimits.max_options) { return tmp.push(''); } diff --git a/app/javascript/mastodon/initial_state.js b/app/javascript/mastodon/initial_state.js index bb6cd12772..7d07ccd6b0 100644 --- a/app/javascript/mastodon/initial_state.js +++ b/app/javascript/mastodon/initial_state.js @@ -122,8 +122,6 @@ export const sso_redirect = getMeta('sso_redirect'); // Glitch-soc-specific settings export const maxChars = (initialState && initialState.max_toot_chars) || 500; - -// CatCatNya~ specific settings -export const pollMinOptions = (initialState && initialState.poll_limits && initialState.poll_limits.min_options) || 2; +export const pollLimits = (initialState && initialState.poll_limits); export default initialState; diff --git a/app/javascript/mastodon/reducers/compose.js b/app/javascript/mastodon/reducers/compose.js index c7914d52e4..383c6d0988 100644 --- a/app/javascript/mastodon/reducers/compose.js +++ b/app/javascript/mastodon/reducers/compose.js @@ -51,7 +51,7 @@ import { import { REDRAFT } from '../actions/statuses'; import { STORE_HYDRATE } from '../actions/store'; import { TIMELINE_DELETE } from '../actions/timelines'; -import { me, pollMinOptions } from '../initial_state'; +import { me, pollLimits } from '../initial_state'; import { unescapeHTML } from '../utils/html'; import { uuid } from '../uuid'; @@ -95,7 +95,7 @@ const initialState = ImmutableMap({ }); const initialPoll = ImmutableMap({ - options: ImmutableList(new Array(pollMinOptions).fill('')), + options: ImmutableList(new Array(pollLimits.min_options ?? 2).fill('')), expires_in: 24 * 3600, multiple: false, }); @@ -281,11 +281,14 @@ const updateSuggestionTags = (state, token) => { }; const updatePoll = (state, index, value) => state.updateIn(['poll', 'options'], options => { - const tmp = options.set(index, value).filterNot(x => x.trim().length === 0); + let tmp = options.set(index, value).filterNot(x => x.trim().length === 0); if (tmp.size === 0) { - return tmp.push('').push(''); - } else if (tmp.size < 4) { + const minOptions = pollLimits.min_options ?? 2; + for (let i = 0; i < minOptions; i++) { + tmp = tmp.push(''); + } + } else if (tmp.size < pollLimits.max_options) { return tmp.push(''); }