Making magic number more readable

This commit is contained in:
Jason Kelly 2021-05-23 14:31:22 +08:00
parent 318e0bf508
commit 7eb5f3b026

View file

@ -3,7 +3,7 @@
let BookWyrm = new class { let BookWyrm = new class {
constructor() { constructor() {
this.MAX_FILE_SIZE = 10000000 this.MAX_FILE_SIZE_BYTES = 10 * 1000000
this.initOnDOMLoaded(); this.initOnDOMLoaded();
this.initReccuringTasks(); this.initReccuringTasks();
this.initEventListeners(); this.initEventListeners();
@ -298,14 +298,14 @@ let BookWyrm = new class {
} }
disableIfTooLarge(eventOrElement) { disableIfTooLarge(eventOrElement) {
const { addRemoveClass, MAX_FILE_SIZE } = this const { addRemoveClass, MAX_FILE_SIZE_BYTES } = this
const element = eventOrElement.currentTarget || eventOrElement const element = eventOrElement.currentTarget || eventOrElement
const submits = element.form.querySelectorAll('[type="submit"]') const submits = element.form.querySelectorAll('[type="submit"]')
const warns = element.parentElement.querySelectorAll('.file-too-big') const warns = element.parentElement.querySelectorAll('.file-too-big')
const isTooBig = element.files && const isTooBig = element.files &&
element.files[0] && element.files[0] &&
element.files[0].size > MAX_FILE_SIZE element.files[0].size > MAX_FILE_SIZE_BYTES
if (isTooBig) { if (isTooBig) {
submits.forEach(submitter => submitter.disabled = true) submits.forEach(submitter => submitter.disabled = true)