Conversation
scripts/main.js
Outdated
|
|
||
| if (pattern.test(postTextValue) && postTextValue.length <= count) { | ||
| textValidate.textContent = 'Данные введены корректно'; | ||
| const sumsCounter = Number(2000) - Number(postTextValue.length); |
There was a problem hiding this comment.
Зачем ты пишешь Number(2000), если 2000 уже изначально число?
scripts/main.js
Outdated
| if (pattern.test(hashtags) && hashtags.length <= 200) { | ||
| textValidateTags.textContent = 'Данные введены корректно'; | ||
| postPublishButton.disabled = false; | ||
| } else if (hashtags.trim() === ' ') { |
There was a problem hiding this comment.
Можешь пояснить, как хэштеги после trim() будут равны пустой строке, если trim удаляет незначащие пробелы с двух сторон?
scripts/main.js
Outdated
| sum = 'Вы вели слишком много символов введите на '+sums+' меньше'; | ||
| postText.style.outlineColor = 'var(--error)' | ||
| textValidateTags.textContent = 'Данные введены неверно'; | ||
| postHashtags.style.outlineColor = 'var(--error)'; |
There was a problem hiding this comment.
Почему ты не хочешь завести CSS-класс и добавлять его на postHashtags в случае не валидного значения?
scripts/main.js
Outdated
|
|
||
| comments.forEach((comment) => { | ||
| commentsContent.innerHTML = ` | ||
| <div class="comments__item"> |
There was a problem hiding this comment.
Лучше использовать шаблон (template), а не вставлять куски HTML. При такой записи легко опечататься, и тогда результат будет непредсказуемым
scripts/main.js
Outdated
| <div class="comments__item"> | ||
| <img | ||
| class="comments__item-avatar" | ||
| src="https://avatars.dicebear.com/api/avataaars/${(Math.random() + 1).toString(36).substring(7)}.svg" |
There was a problem hiding this comment.
Адреса нужно выносить в константу
There was a problem hiding this comment.
Что такое числа 36 и 7? Выглядят как магические числа: https://ru.wikipedia.org/wiki/%D0%9C%D0%B0%D0%B3%D0%B8%D1%87%D0%B5%D1%81%D0%BA%D0%BE%D0%B5_%D1%87%D0%B8%D1%81%D0%BB%D0%BE_(%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%BC%D0%B8%D1%80%D0%BE%D0%B2%D0%B0%D0%BD%D0%B8%D0%B5)
scripts/main.js
Outdated
| commentsButton.addEventListener('click', () => { | ||
| const comment = postComment.value; | ||
| if (comment.trim() === '') { | ||
| console.log('error'); |
There was a problem hiding this comment.
Вывода в консоль быть не должно
scripts/main.js
Outdated
| const likeButton = document.querySelector('.fa-heart'); | ||
| const countElement = document.querySelector('#like'); | ||
| const statisticsLikes = document.querySelector('.statistics__likes'); | ||
| let likes = 0; |
There was a problem hiding this comment.
У тебя одна глобальная переменная с количеством лайков на все посты?
scripts/main.js
Outdated
| let likes = 0; | ||
|
|
||
| likeButton.addEventListener('click', () => { | ||
| likes++; |
There was a problem hiding this comment.
Тебе нужно сначала отправить запрос на сервер, и только когда он ответит, что все ок, ты увеличиваешь количество лайков
scripts/main.js
Outdated
| getItemId(); | ||
| }); | ||
|
|
||
| const countLikesPost = (content) => { |
There was a problem hiding this comment.
Точно ли нужна под это функция?
scripts/main.js
Outdated
| }; | ||
|
|
||
| const updateCount = (itemId) => { | ||
| countElement.innerHTML = likes; |
There was a problem hiding this comment.
Используешь глобальную переменную для лайков. Не надо так
scripts/main.js
Outdated
| const imageAvatar = document.querySelector('#profile-avatar'); | ||
|
|
||
| const getBioUser = () => { | ||
| const response = fetch('https://c-gallery.polinashneider.space/api/v1/users/me/', { |
scripts/main.js
Outdated
| const formData = new FormData(); | ||
| formData.append("photo", filUploadAvatar.files[0]); | ||
|
|
||
| fetch('https://c-gallery.polinashneider.space/api/v1/users/me/', { |
scripts/main.js
Outdated
| textValidate.textContent = 'Поле обязательно для заполнения'; | ||
| postPublishButton.disabled = true; | ||
| } else if (postTextValue.length === 2000) { | ||
| const sumsCounter = Number(2000) - Number(postTextValue.length); |
There was a problem hiding this comment.
Штуковину с Number(2000) нужно поправить везде
scripts/main.js
Outdated
| } else if (postTextValue === '') { | ||
| textValidate.textContent = 'Поле обязательно для заполнения'; | ||
| postPublishButton.disabled = true; | ||
| } else if (postTextValue.length === 2000) { |
There was a problem hiding this comment.
У тебя же есть переменная count. Почему бы в коде не использовать ее?
| postPublishButton.disabled = true; | ||
| } else { | ||
| textValidateTags.textContent = 'Данные введены неверно'; | ||
| postHashtags.classList.add('error-validate'); |
scripts/main.js
Outdated
|
|
||
| const inputsAddPublish = document.querySelectorAll('textarea'); | ||
|
|
||
| for (let i = 0; i < inputsAddPublish.length; i++) { |
There was a problem hiding this comment.
Можешь пояснить, зачем тебе тут цикл? Получается, ты inputsAddPublish.length раз сбрасываешь значения одних и тех же элементов. У тебя даже i в теле цикла не фигурирует
scripts/main.js
Outdated
| document.body.classList.remove('with-overlay'); | ||
| getPostUsers(); | ||
|
|
||
| showMessage('#alert-success'); |
There was a problem hiding this comment.
У тебя всегда один и тот же текст показывается в случае успеха?
scripts/main.js
Outdated
| if (isHidden) { | ||
| loader.removeAttribute('hidden'); | ||
| } else { | ||
| loader.setAttribute('hidden', ''); |
There was a problem hiding this comment.
У вас есть критерий про использование одного API. Где-то ты используешь el.disabled = true, а где-то el.setAttribute('hidden', '')
Нужно унифицировать. То есть либо через точку обращаться к атрибуту, либо через setAttribute
| }); | ||
| } | ||
| createAvatarUser(); | ||
|
|
There was a problem hiding this comment.
Много пустых строк в конце файла. Зачем?
scripts/utils.js
Outdated
| commentsButton.addEventListener('click', () => { | ||
| const comment = postComment.value; | ||
| if (comment === '') { | ||
| showMessage('#alert-fail'); |
There was a problem hiding this comment.
Если комментарий пустой, можно не показывать уведомление, а просто блокировать кнопку добавления, например
scripts/utils.js
Outdated
| commentsContent.dataset.postId = id; | ||
|
|
||
| comments.forEach((comment) => { | ||
| const dateCommnets = new Date(comment.created_at); |
scripts/utils.js
Outdated
|
|
||
| const commentsAvatar = document.createElement('img'); | ||
| commentsAvatar.className = 'comments__item-avatar'; | ||
| commentsAvatar.src = `https://avatars.dicebear.com/api/avataaars/${(Math.random() + 1)}.svg`; |
There was a problem hiding this comment.
Такое лучше выносить в константу (адрес) — я вроде про это писала
scripts/utils.js
Outdated
| commentTime.className = 'comments__item-time'; | ||
| commentTime.innerText = newDateComments; | ||
|
|
||
| commentsText.append(commentNickname); |
There was a problem hiding this comment.
Возможно, тебе было бы удобнее использовать template, а не собирать такую сложную матрешку. Вы можете менять верстку на свое усмотрение
scripts/utils.js
Outdated
| showMessage('#alert-fail'); | ||
| }) | ||
| .finally(() => { | ||
| previewPostModal.classList.remove('active'); |
There was a problem hiding this comment.
Выглядит как повторяющийся код, который можно вынести в функцию
| if (comment === '') { | ||
| showMessage('#alert-fail'); | ||
| } else { | ||
| sendComment(comment, id); |
There was a problem hiding this comment.
У меня почему-то не срабатывает добавление комментариев, но, может, на пейджес старая версия
PolinaShneider
left a comment
There was a problem hiding this comment.
Ты все еще пишешь код в реквесте, который открыт в репозиторий школы. Почти все хорошо, но тебе нужно открыть его в свой репозиторий, иначе защита проекта будет невозможна 😿
No description provided.