Skip to content

Commit 76203c6

Browse files
authored
Merge pull request #14 from bearBenjamin/module12-task2
refactor: внес изменения для прохождения тестов
2 parents b21604f + a62e573 commit 76203c6

File tree

5 files changed

+32
-43
lines changed

5 files changed

+32
-43
lines changed

index.html

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,11 @@ <h2 class="img-upload__title visually-hidden">Загрузка фотограф
121121
minlength="2" maxlength="104"
122122
data-pristine-minlength-message="Минимальная длина 2 символа"
123123
data-pristine-maxlength-message="Максимальная длина 104 символа">
124-
125124
</div>
126125
<div class="img-upload__field-wrapper">
127-
<textarea class="text__description" name="description" placeholder="Ваш комментарий..."
128-
minlength="2" maxlength="140"
129-
data-pristine-minlength-message="Минимальная длина 2 символа"
130-
data-pristine-maxlength-message="Максимальная длина 140 символов"></textarea>
126+
<textarea class="text__description" name="description" placeholder="Ваш комментарий..."></textarea>
131127
</div>
132128
</fieldset>
133-
134129
<!-- Кнопка для отправки данных на сервер -->
135130
<button type="submit" class="img-upload__submit" id="upload-submit">Опубликовать</button>
136131
</div>

js/filter.js

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { renderPreview } from './preview-photo.js';
22
import { getCurrentData } from './full-photo.js';
33
import { debounce } from './utils.js';
44

5+
const TIME_DELAY = 500;
6+
57
const pictureContainer = document.querySelector('.pictures.container');
68

79
const filterContainer = document.querySelector('.img-filters');
@@ -27,20 +29,7 @@ const showPhotos = (dataPhotos) => {
2729
getCurrentData(dataPhotos);
2830
};
2931

30-
const showPhotosDebounce = debounce((data) => showPhotos(data));
31-
32-
// const shuffleData = (dataPhotos, count = 10) => {
33-
// const array = [...dataPhotos];
34-
// let randomIndex;
35-
36-
// for (let i = array.length - 1; i > 0; i -= 1) {
37-
// randomIndex = Math.floor(Math.random() * (i + 1));
38-
39-
// [array[i], array[randomIndex]] = [array[randomIndex], array[i]];
40-
// }
41-
42-
// return array.slice(0, Math.min(count, array.length));
43-
// };
32+
const showPhotosDebounce = debounce((data, time) => showPhotos(data, time));
4433

4534
const getRandomPhoto = (dataPhoto) => {
4635
const result = [];
@@ -82,18 +71,18 @@ const getFilterPhotos = (dataPhotos) => {
8271

8372
switch(btn.id) {
8473
case ('filter-default'):
85-
showPhotosDebounce(dataPhotos);
74+
showPhotosDebounce(dataPhotos, TIME_DELAY);
8675
break;
8776

8877
case ('filter-random'): {
8978
const newDataPhotos = getRandomPhoto(dataPhotos);
90-
showPhotosDebounce(newDataPhotos);
79+
showPhotosDebounce(newDataPhotos, TIME_DELAY);
9180
break;
9281
}
9382

9483
case ('filter-discussed'): {
9584
const newDataPhotos = sortMessageAmount(dataPhotos);
96-
showPhotosDebounce(newDataPhotos);
85+
showPhotosDebounce(newDataPhotos, TIME_DELAY);
9786
break;
9887
}
9988
}

js/form.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pristine.addValidator(fieldHashtag, isHashtag, 'Неверный хэш-тег',
3131
pristine.addValidator(fieldHashtag, isDubleHashtags, 'Хэш-теги дублируются', 2, false);
3232
pristine.addValidator(fieldHashtag, isLengthHashtags, 'Не более пяти хэш-тегов', 3, false);
3333

34-
pristine.addValidator(fieldDescription, isCommentLength, false);
34+
pristine.addValidator(fieldDescription, isCommentLength, 'Не более 140 символов', false);
3535

3636
const showModalEditing = () => {
3737
modalEditing.classList.remove('hidden');
@@ -56,7 +56,6 @@ const onFieldLoadChange = (evt) => {
5656
});
5757
}
5858

59-
6059
showModalEditing();
6160
};
6261

@@ -69,7 +68,7 @@ const onBtnCloseClick = () => {
6968
document.removeEventListener('keydown', onModalEditingEscKeydown);
7069
};
7170

72-
fieldLoadFile.addEventListener('change', onFieldLoadChange);
71+
//fieldLoadFile.addEventListener('change', onFieldLoadChange);
7372

7473
const blockBtnSubmit = () => {
7574
btnSubmitForm.disabled = true;
@@ -92,17 +91,19 @@ const initFormSubmit = () => {
9291
.then(() => {
9392
showSucces();
9493
onBtnCloseClick();
94+
unBlockBtnSubmit();
9595
})
9696
.catch(() => {
9797
showError();
98+
unBlockBtnSubmit();
9899
});
99-
unBlockBtnSubmit();
100+
100101
}
101102
});
102-
103-
btnCloseForm.addEventListener('click', onBtnCloseClick);
104103
};
105104

105+
btnCloseForm.addEventListener('click', onBtnCloseClick);
106+
106107
function onModalEditingEscKeydown (evt) {
107108
if (fieldHashtag === document.activeElement || fieldDescription === document.activeElement) {
108109
return evt;
@@ -114,4 +115,4 @@ function onModalEditingEscKeydown (evt) {
114115
}
115116
}
116117

117-
export { initFormSubmit, onModalEditingEscKeydown };
118+
export { initFormSubmit, onModalEditingEscKeydown, onFieldLoadChange };

js/main.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import { initFormSubmit } from './form.js';
1+
import { initFormSubmit, onFieldLoadChange } from './form.js';
22
import { getData } from './fetch.js';
33
import { showAlert } from './modal-message-user.js';
44
import { getFilterPhotos } from './filter.js';
55

6-
const init = () => {
7-
getData()
8-
.then((dataPhotos) => {
9-
getFilterPhotos(dataPhotos);
10-
})
11-
.catch(() => {
12-
showAlert();
13-
});
14-
initFormSubmit();
15-
};
166

17-
init();
7+
const fieldLoadFileElement = document.querySelector('#upload-file');
8+
9+
fieldLoadFileElement.addEventListener('change', onFieldLoadChange);
10+
11+
getData()
12+
.then((dataPhotos) => {
13+
getFilterPhotos(dataPhotos);
14+
})
15+
.catch(() => {
16+
showAlert();
17+
});
18+
19+
initFormSubmit();
20+
21+

js/modal-message-user.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const showError = () => {
8888
const templateShowError = document.querySelector('#error').content;
8989
const newTemplateShowError = templateShowError.querySelector('.error');
9090
const cloneShowError = newTemplateShowError.cloneNode(true);
91-
cloneShowError.setAttribute('style', 'z-index: 3');
91+
//cloneShowError.setAttribute('style', 'z-index: 3');
9292

9393
document.body.append(cloneShowError);
9494

0 commit comments

Comments
 (0)