Skip to content

Commit 1e28574

Browse files
authored
Merge pull request #17 from PAVLUXAN/master
2 parents a99ff90 + f9fdf35 commit 1e28574

File tree

5 files changed

+24
-32
lines changed

5 files changed

+24
-32
lines changed

js/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { getData } from './api.js';
44
import { showErrorGetting } from './messages.js';
55
import { initFilter, setPhotos } from './filter.js';
66

7-
initFilter(renderPhotos);
87
getData().then((response) => {
98
if (response.hasError) {
109
showErrorGetting();
1110
return;
1211
}
12+
initFilter(renderPhotos);
1313
const { data = [] } = response;
1414
setPhotos(data);
1515
});

js/messages.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,6 @@ export const showErrorSending = () => {
7171

7272
export const showErrorGetting = () => {
7373
const errorNotify = getErrorTemplate.cloneNode(true);
74-
const errorTitle = errorNotify.querySelector('.data-error__title');
75-
76-
errorTitle.style.zIndex = '100';
77-
errorTitle.style.position = 'absolute';
78-
errorTitle.style.left = '0';
79-
errorTitle.style.top = '0';
80-
errorTitle.style.right = '0';
81-
errorTitle.style.padding = '10px 3px';
82-
errorTitle.style.fontSize = '20px';
83-
errorTitle.style.textAlign = 'center';
84-
errorTitle.style.backgroundColor = 'red';
85-
8674
document.body.append(errorNotify);
8775

8876
setTimeout(() => {

js/render-big-photo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const bigPhotoForm = document.querySelector('.big-picture');
55
const bigPhotoImgOverlay = bigPhotoForm
66
.querySelector('.big-picture__img')
77
.querySelector('img');
8-
const bigPhotolikesCount = bigPhotoForm.querySelector('.likes-count');
8+
const bigPhotoLikesCount = bigPhotoForm.querySelector('.likes-count');
99
const bigPhotoCaption = bigPhotoForm.querySelector('.social__caption');
1010
const bigPhotoCancelButton = bigPhotoForm.querySelector('.big-picture__cancel');
1111

@@ -32,7 +32,7 @@ const closeBigPicture = () => {
3232
export const openBigPhoto = (photo) => {
3333
const currentPhoto = photo;
3434
bigPhotoImgOverlay.src = currentPhoto.url;
35-
bigPhotolikesCount.textContent = currentPhoto.likes;
35+
bigPhotoLikesCount.textContent = currentPhoto.likes;
3636
bigPhotoCaption.textContent = currentPhoto.description;
3737

3838
renderComments(currentPhoto.comments);

js/slider-effects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ noUiSlider.create(slider, {
2424
});
2525

2626
slider.noUiSlider.on('update', () => {
27-
effectLevelValue.value = slider.noUiSlider.get();
27+
effectLevelValue.value = Number(slider.noUiSlider.get());
2828
});
2929

3030
effectLevelOverlay.classList.add('hidden');

js/validator.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,26 @@ import { selectPluralForm } from './util.js';
33
const MAX_HASHTAGS = 5;
44
const MAX_SYMBOLS_HASHTAG = 20;
55
const 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

1118
export 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

7078
export 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

Comments
 (0)