Handle character limit in initial state in frontend.
This commit is contained in:
		
							parent
							
								
									f1bfcb50f0
								
							
						
					
					
						commit
						6bae583d2f
					
				@ -17,6 +17,7 @@ import { isMobile } from '../../../is_mobile';
 | 
				
			|||||||
import ImmutablePureComponent from 'react-immutable-pure-component';
 | 
					import ImmutablePureComponent from 'react-immutable-pure-component';
 | 
				
			||||||
import { length } from 'stringz';
 | 
					import { length } from 'stringz';
 | 
				
			||||||
import { countableText } from '../util/counter';
 | 
					import { countableText } from '../util/counter';
 | 
				
			||||||
 | 
					import { maxChars } from '../../../initial_state';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';
 | 
					const allowedAroundShortCode = '><\u0085\u0020\u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u2028\u2029\u0009\u000a\u000b\u000c\u000d';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -80,7 +81,7 @@ export default class ComposeForm extends ImmutablePureComponent {
 | 
				
			|||||||
    const { is_submitting, is_uploading, anyMedia } = this.props;
 | 
					    const { is_submitting, is_uploading, anyMedia } = this.props;
 | 
				
			||||||
    const fulltext = [this.props.spoiler_text, countableText(this.props.text)].join('');
 | 
					    const fulltext = [this.props.spoiler_text, countableText(this.props.text)].join('');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (is_submitting || is_uploading || length(fulltext) > 500 || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
 | 
					    if (is_submitting || is_uploading || length(fulltext) > maxChars || (fulltext.length !== 0 && fulltext.trim().length === 0 && !anyMedia)) {
 | 
				
			||||||
      return;
 | 
					      return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -158,7 +159,7 @@ export default class ComposeForm extends ImmutablePureComponent {
 | 
				
			|||||||
    const { intl, onPaste, showSearch, anyMedia } = this.props;
 | 
					    const { intl, onPaste, showSearch, anyMedia } = this.props;
 | 
				
			||||||
    const disabled = this.props.is_submitting;
 | 
					    const disabled = this.props.is_submitting;
 | 
				
			||||||
    const text     = [this.props.spoiler_text, countableText(this.props.text)].join('');
 | 
					    const text     = [this.props.spoiler_text, countableText(this.props.text)].join('');
 | 
				
			||||||
    const disabledButton = disabled || this.props.is_uploading || length(text) > 500 || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
 | 
					    const disabledButton = disabled || this.props.is_uploading || length(text) > maxChars || (text.length !== 0 && text.trim().length === 0 && !anyMedia);
 | 
				
			||||||
    let publishText = '';
 | 
					    let publishText = '';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
 | 
					    if (this.props.privacy === 'private' || this.props.privacy === 'direct') {
 | 
				
			||||||
@ -210,7 +211,7 @@ export default class ComposeForm extends ImmutablePureComponent {
 | 
				
			|||||||
            <SensitiveButtonContainer />
 | 
					            <SensitiveButtonContainer />
 | 
				
			||||||
            <SpoilerButtonContainer />
 | 
					            <SpoilerButtonContainer />
 | 
				
			||||||
          </div>
 | 
					          </div>
 | 
				
			||||||
          <div className='character-counter__wrapper'><CharacterCounter max={500} text={text} /></div>
 | 
					          <div className='character-counter__wrapper'><CharacterCounter max={maxChars} text={text} /></div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        <div className='compose-form__publish'>
 | 
					        <div className='compose-form__publish'>
 | 
				
			||||||
 | 
				
			|||||||
@ -11,5 +11,6 @@ export const boostModal = getMeta('boost_modal');
 | 
				
			|||||||
export const deleteModal = getMeta('delete_modal');
 | 
					export const deleteModal = getMeta('delete_modal');
 | 
				
			||||||
export const me = getMeta('me');
 | 
					export const me = getMeta('me');
 | 
				
			||||||
export const searchEnabled = getMeta('search_enabled');
 | 
					export const searchEnabled = getMeta('search_enabled');
 | 
				
			||||||
 | 
					export const maxChars = getMeta('max_toot_chars') || 500;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export default initialState;
 | 
					export default initialState;
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user