-
Notifications
You must be signed in to change notification settings - Fork 2
Code review #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Code review #1
Conversation
static/upload_module/template.html
Outdated
| <body> | ||
|
|
||
| <p>Здесь HTML-код компонента.</p> | ||
| <div class="module__upload"></div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Инициализация модуля через один <div> элемент - это прекрасное минималистичное решение. Но просьба выбрать более специфичное имя для базового класса, например: multiple-issues-upload.
Плюс к этому, если используется методология БЭМ, то класс module__upload как "элемент" обязан находиться внутри элемента с классом module как "блока". Так что предлагаю либо отказаться от использования БЭМ в принципе (для такого маленького проекта он не нужен), либо пересмотреть нейминг: https://cssguidelin.es/#bem-like-naming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Стоит добавить один дата-атрибут для определения числа выпусков в комиксе: data-issues-count чтобы правильно нумеровать новые страницы.
static/upload_module/template.html
Outdated
| <link rel="stylesheet" href="style.css"> | ||
| <link rel="stylesheet" href="modal.css"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если можно, это лучше объединить в один файл, чтобы модуль было проще подключать.
static/upload_module/main.js
Outdated
| @@ -0,0 +1,290 @@ | |||
| (function () { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если везде используются стрелочные функции, то и тут можно.
static/upload_module/main.js
Outdated
| @@ -0,0 +1,290 @@ | |||
| (function () { | |||
| const Page = ` | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нейминг. Константы (не путать с константными переменными) в программировании называются капсом, например: PAGE_HTML_TEMPLATE;
static/upload_module/main.js
Outdated
| <a href="#" class="upload__card__button upload__card__button_move-left upload__card__button_move-left-${index}"> | ||
| <img class="image-fit" src="images/left-arrow.svg" alt="Передвинуть влево"> | ||
| </a> | ||
| <h5 class="upload__card__title">${name}</h5> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
${name} - это потенциальное место для XSS-атаки. Все данные, которые приходит от пользователя, нужно вставлять через https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/innerText
static/upload_module/main.js
Outdated
| files_.push(createFile(elem)); | ||
| count++; | ||
| } | ||
| dropbox.classList.add("upload__dropbox-disabled"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Зону загрузки точно нужно отключать после первой пачки файлов? А если автор решит закинуть еще что-то?
static/upload_module/main.js
Outdated
|
|
||
| const createFileCard = (elem, index) => { | ||
| const card = document.createElement("div"); | ||
| card.className = `upload__card upload__card-${index}`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, класс upload__card upload__card-${index} нигде не используется. Я рекомендую сохранить индекс через дата-атрибут и использовать его дальше в коде (например, в обработчиках кнопок).
| return card; | ||
| } | ||
|
|
||
| const createFile = (file, name = "", description = "") => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется, параметры name = "", description = "" нигде не используются.
static/upload_module/main.js
Outdated
| formElement.setAttribute('action', '/action/manageAddIssue'); | ||
| formElement.enctype = 'multipart/form-data'; | ||
|
|
||
| const idComic = document.createElement('input'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нейминг. Переменные называются по правилам английского языка: в английском существительные ставятся в обратном порядке: например, идентификатор комикса - это "comicsId" а не "idComics"
| list.items.add(elem.file); | ||
| image.files = list.files; | ||
|
|
||
| image.setAttribute('data-limit', '2097152') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Размер стоит проверять в момент, когда автор изначально добавляет файлы.
Codestyle fix
Loading animation
PR for code review