Improve min poll options, expose value in API

This commit is contained in:
Jeremy Kescher 2022-11-01 10:29:44 +01:00
parent 22427cd43c
commit 9c8fb2d475
No known key found for this signature in database
GPG key ID: 48DFE4BB15BA5940
8 changed files with 14 additions and 5 deletions

View file

@ -81,7 +81,7 @@ class Option extends React.PureComponent {
</label> </label>
<div className='poll__cancel'> <div className='poll__cancel'>
<IconButton disabled={index < 1} title={intl.formatMessage(messages.remove_option)} icon='times' onClick={this.handleOptionRemove} /> <IconButton disabled={index < pollLimits.min_options} title={intl.formatMessage(messages.remove_option)} icon='times' onClick={this.handleOptionRemove} />
</div> </div>
</li> </li>
); );

View file

@ -60,6 +60,7 @@ import { me, defaultContentType } from 'flavours/glitch/initial_state';
import { overwrite } from 'flavours/glitch/utils/js_helpers'; import { overwrite } from 'flavours/glitch/utils/js_helpers';
import { unescapeHTML } from 'flavours/glitch/utils/html'; import { unescapeHTML } from 'flavours/glitch/utils/html';
import { recoverHashtags } from 'flavours/glitch/utils/hashtag'; import { recoverHashtags } from 'flavours/glitch/utils/hashtag';
import { pollLimits } from 'flavours/glitch/initial_state';
const totalElefriends = 3; const totalElefriends = 3;
@ -127,7 +128,7 @@ const initialState = ImmutableMap({
}); });
const initialPoll = ImmutableMap({ const initialPoll = ImmutableMap({
options: ImmutableList(['']), options: ImmutableList(new Array(pollLimits.min_options).fill('')),
expires_in: 24 * 3600, expires_in: 24 * 3600,
multiple: false, multiple: false,
}); });

View file

@ -7,6 +7,7 @@ import IconButton from 'mastodon/components/icon_button';
import Icon from 'mastodon/components/icon'; import Icon from 'mastodon/components/icon';
import AutosuggestInput from 'mastodon/components/autosuggest_input'; import AutosuggestInput from 'mastodon/components/autosuggest_input';
import classNames from 'classnames'; import classNames from 'classnames';
import { pollLimits } from 'mastodon/initial_state';
const messages = defineMessages({ const messages = defineMessages({
option_placeholder: { id: 'compose_form.poll.option_placeholder', defaultMessage: 'Choice {number}' }, option_placeholder: { id: 'compose_form.poll.option_placeholder', defaultMessage: 'Choice {number}' },
@ -102,7 +103,7 @@ class Option extends React.PureComponent {
</label> </label>
<div className='poll__cancel'> <div className='poll__cancel'>
<IconButton disabled={index < 1} title={intl.formatMessage(messages.remove_option)} icon='times' onClick={this.handleOptionRemove} /> <IconButton disabled={index < pollLimits.min_options} title={intl.formatMessage(messages.remove_option)} icon='times' onClick={this.handleOptionRemove} />
</div> </div>
</li> </li>
); );

View file

@ -129,4 +129,7 @@ export const version = getMeta('version');
export const translationEnabled = getMeta('translation_enabled'); export const translationEnabled = getMeta('translation_enabled');
export const languages = initialState?.languages; export const languages = initialState?.languages;
// CatCatNya~ specific setting for vanilla flavor
export const pollLimits = (initialState && initialState.poll_limits);
export default initialState; export default initialState;

View file

@ -52,7 +52,7 @@ import { STORE_HYDRATE } from '../actions/store';
import { REDRAFT } from '../actions/statuses'; import { REDRAFT } from '../actions/statuses';
import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable'; import { Map as ImmutableMap, List as ImmutableList, OrderedSet as ImmutableOrderedSet, fromJS } from 'immutable';
import uuid from '../uuid'; import uuid from '../uuid';
import { me } from '../initial_state'; import { me, pollLimits } from '../initial_state';
import { unescapeHTML } from '../utils/html'; import { unescapeHTML } from '../utils/html';
const initialState = ImmutableMap({ const initialState = ImmutableMap({
@ -95,7 +95,7 @@ const initialState = ImmutableMap({
}); });
const initialPoll = ImmutableMap({ const initialPoll = ImmutableMap({
options: ImmutableList(['']), options: ImmutableList(new Array(pollLimits.min_options).fill('')),
expires_in: 24 * 3600, expires_in: 24 * 3600,
multiple: false, multiple: false,
}); });

View file

@ -17,6 +17,7 @@ class InitialStateSerializer < ActiveModel::Serializer
def poll_limits def poll_limits
{ {
min_options: PollValidator::MIN_OPTIONS,
max_options: PollValidator::MAX_OPTIONS, max_options: PollValidator::MAX_OPTIONS,
max_option_chars: PollValidator::MAX_OPTION_CHARS, max_option_chars: PollValidator::MAX_OPTION_CHARS,
min_expiration: PollValidator::MIN_EXPIRATION, min_expiration: PollValidator::MIN_EXPIRATION,

View file

@ -67,6 +67,7 @@ class REST::InstanceSerializer < ActiveModel::Serializer
}, },
polls: { polls: {
min_options: PollValidator::MIN_OPTIONS,
max_options: PollValidator::MAX_OPTIONS, max_options: PollValidator::MAX_OPTIONS,
max_characters_per_option: PollValidator::MAX_OPTION_CHARS, max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
min_expiration: PollValidator::MIN_EXPIRATION, min_expiration: PollValidator::MIN_EXPIRATION,

View file

@ -42,6 +42,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
def poll_limits def poll_limits
{ {
min_options: PollValidator::MIN_OPTIONS,
max_options: PollValidator::MAX_OPTIONS, max_options: PollValidator::MAX_OPTIONS,
max_option_chars: PollValidator::MAX_OPTION_CHARS, max_option_chars: PollValidator::MAX_OPTION_CHARS,
min_expiration: PollValidator::MIN_EXPIRATION, min_expiration: PollValidator::MIN_EXPIRATION,
@ -91,6 +92,7 @@ class REST::V1::InstanceSerializer < ActiveModel::Serializer
}, },
polls: { polls: {
min_options: PollValidator::MIN_OPTIONS,
max_options: PollValidator::MAX_OPTIONS, max_options: PollValidator::MAX_OPTIONS,
max_characters_per_option: PollValidator::MAX_OPTION_CHARS, max_characters_per_option: PollValidator::MAX_OPTION_CHARS,
min_expiration: PollValidator::MIN_EXPIRATION, min_expiration: PollValidator::MIN_EXPIRATION,