Skip to content

Commit

Permalink
[Glitch] Use the server setting to get the max number of poll options…
Browse files Browse the repository at this point in the history
… in UI

Port b9722df to glitch-soc

Signed-off-by: Claire <[email protected]>
  • Loading branch information
renchap authored and ClearlyClaire committed Mar 11, 2024
1 parent efbc8cb commit 6440651
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/javascript/flavours/glitch/actions/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions app/javascript/flavours/glitch/reducers/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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('');
}

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 6440651

Please sign in to comment.