@@ -3,18 +3,26 @@ import { selectPluralForm } from './util.js';
33const MAX_HASHTAGS = 5 ;
44const MAX_SYMBOLS_HASHTAG = 20 ;
55const MAX_SYMBOLS_COMMENT = 140 ;
6+ const TEXT_LENGTH_MOST_BE_LESS_OR_EQUAL = 'Длина текста должна быть меньше или равна 140 символов' ;
67
7- let errorMessage = '' ;
8+ //let errorMessage = '';
9+
10+ const errors = {
11+ hashtags : '' ,
12+ description : ''
13+ } ;
14+
15+ export const getError = ( ) => Object . values ( errors ) . filter ( Boolean ) . join ( ' и ' ) ;
816
9- export const getError = ( ) => errorMessage ;
1017
1118export const isHashtagsValid = ( value ) => {
12- errorMessage = '' ;
19+ errors . hashtags = '' ;
20+ const isDescriptonError = ! errors . description . length ;
1321
1422 const inputText = value . toLowerCase ( ) . trim ( ) ;
1523
1624 if ( ! value . trim ( ) ) {
17- return true ;
25+ return isDescriptonError ;
1826 }
1927
2028 const hashTags = inputText . split ( / \s + / ) ;
@@ -61,26 +69,22 @@ export const isHashtagsValid = (value) => {
6169 return rules . every ( ( rule ) => {
6270 const isInvalid = rule . isInvalid ( ) ;
6371 if ( isInvalid ) {
64- errorMessage = rule . error ;
72+ errors . hashtags = rule . error ;
6573 }
6674 return ! isInvalid ;
67- } ) ;
75+ } ) && isDescriptonError ;
6876} ;
6977
7078export const isDescriptionValid = ( value ) => {
71- errorMessage = '' ;
72-
79+ errors . description = '' ;
80+ const isHashtagsError = ! errors . hashtags . length ;
7381 if ( ! value ) {
74- return true ;
82+ return isHashtagsError ;
7583 }
7684
77- const rule = {
78- check : value . length >= MAX_SYMBOLS_COMMENT ,
79- error : 'Длина текста должна быть меньше или равна 140 символов' ,
80- } ;
81- const isInvalid = rule . check ;
85+ const isInvalid = value . length >= MAX_SYMBOLS_COMMENT ;
8286 if ( isInvalid ) {
83- errorMessage = rule . error ;
87+ errors . description = TEXT_LENGTH_MOST_BE_LESS_OR_EQUAL ;
8488 }
85- return ! isInvalid ;
89+ return ! isInvalid && isHashtagsError ;
8690} ;
0 commit comments