[Glitch] Use the server setting to get the max number of poll options in UI

Port b9722dfe2b to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
main
Renaud Chaput 2024-03-11 10:13:35 +01:00 committed by Claire
parent efbc8cba17
commit 6440651976
3 changed files with 9 additions and 7 deletions

View File

@ -822,11 +822,12 @@ export function addPollOption(title) {
}; };
} }
export function changePollOption(index, title) { export function changePollOption(index, title, maxOptions) {
return { return {
type: COMPOSE_POLL_OPTION_CHANGE, type: COMPOSE_POLL_OPTION_CHANGE,
index, index,
title, title,
maxOptions,
}; };
} }

View File

@ -59,10 +59,11 @@ const Option = ({ multipleChoice, index, title, autoFocus }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const suggestions = useSelector(state => state.getIn(['compose', 'suggestions'])); const suggestions = useSelector(state => state.getIn(['compose', 'suggestions']));
const lang = useSelector(state => state.getIn(['compose', 'language'])); 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 } }) => { const handleChange = useCallback(({ target: { value } }) => {
dispatch(changePollOption(index, value)); dispatch(changePollOption(index, value, maxOptions));
}, [dispatch, index]); }, [dispatch, index, maxOptions]);
const handleSuggestionsFetchRequested = useCallback(token => { const handleSuggestionsFetchRequested = useCallback(token => {
dispatch(fetchComposeSuggestions(token)); dispatch(fetchComposeSuggestions(token));

View File

@ -54,7 +54,7 @@ import {
import { REDRAFT } from '../actions/statuses'; import { REDRAFT } from '../actions/statuses';
import { STORE_HYDRATE } from '../actions/store'; import { STORE_HYDRATE } from '../actions/store';
import { TIMELINE_DELETE } from '../actions/timelines'; 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 { recoverHashtags } from '../utils/hashtag';
import { unescapeHTML } from '../utils/html'; import { unescapeHTML } from '../utils/html';
import { overwrite } from '../utils/js_helpers'; 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); const tmp = options.set(index, value).filterNot(x => x.trim().length === 0);
if (tmp.size === 0) { if (tmp.size === 0) {
return tmp.push('').push(''); return tmp.push('').push('');
} else if (tmp.size < pollLimits.max_options) { } else if (tmp.size < maxOptions) {
return tmp.push(''); return tmp.push('');
} }
@ -649,7 +649,7 @@ export default function compose(state = initialState, action) {
case COMPOSE_POLL_REMOVE: case COMPOSE_POLL_REMOVE:
return state.set('poll', null); return state.set('poll', null);
case COMPOSE_POLL_OPTION_CHANGE: 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: case COMPOSE_POLL_SETTINGS_CHANGE:
return state.update('poll', poll => poll.set('expires_in', action.expiresIn).set('multiple', action.isMultiple)); return state.update('poll', poll => poll.set('expires_in', action.expiresIn).set('multiple', action.isMultiple));
case COMPOSE_LANGUAGE_CHANGE: case COMPOSE_LANGUAGE_CHANGE: