[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>
This commit is contained in:
parent
efbc8cba17
commit
6440651976
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue