Jelajahi Sumber

refactor(js): use template literals for string concatenation to improve readability

Frédéric Guillot 3 bulan lalu
induk
melakukan
79a3369699

+ 3 - 3
internal/ui/static/js/app.js

@@ -284,7 +284,7 @@ function showToastNotification(iconType, notificationMessage) {
  * @param {boolean} reloadOnFail - If true, reload the current page if the target page is not found.
  */
 function goToPage(page, reloadOnFail = false) {
-    const element = document.querySelector(":is(a, button)[data-page=" + page + "]");
+    const element = document.querySelector(`:is(a, button)[data-page=${page}]`);
 
     if (element) {
         document.location.href = element.href;
@@ -649,7 +649,7 @@ function toggleEntryStatus(element, toasting) {
             showToastNotification(newStatus, currentStatus === "read" ? buttonElement.dataset.toastUnread : buttonElement.dataset.toastRead);
         }
 
-        element.classList.replace("item-status-" + currentStatus, "item-status-" + newStatus);
+        element.classList.replace(`item-status-${currentStatus}`, `item-status-${newStatus}`);
 
         if (isListView() && getVisibleEntries().length === 0) {
             window.location.reload();
@@ -953,7 +953,7 @@ function handleConfirmationMessage(linkElement, callback) {
     };
 
     questionElement.className = "confirm";
-    questionElement.appendChild(document.createTextNode(linkElement.dataset.labelQuestion + " "));
+    questionElement.appendChild(document.createTextNode(`${linkElement.dataset.labelQuestion} `));
     questionElement.appendChild(yesElement);
     questionElement.appendChild(document.createTextNode(", "));
     questionElement.appendChild(noElement);

+ 1 - 1
internal/ui/static/js/touch_handler.js

@@ -62,7 +62,7 @@ class TouchHandler {
 
             const tx = (absDistance > 75 ? Math.sqrt(absDistance - 75) + 75 : absDistance) * Math.sign(distance);
 
-            this.touch.element.style.transform = "translateX(" + tx + "px)";
+            this.touch.element.style.transform = `translateX(${tx}px)`;
 
             event.preventDefault();
         }

+ 4 - 4
internal/ui/static/js/webauthn_handler.js

@@ -48,7 +48,7 @@ class WebAuthnHandler {
     async post(urlKey, username, data) {
         let url = document.body.dataset[urlKey];
         if (username) {
-            url += "?username=" + encodeURIComponent(username);
+            url += `?username=${encodeURIComponent(username)}`;
         }
 
         return sendPOSTRequest(url, data);
@@ -57,7 +57,7 @@ class WebAuthnHandler {
     async get(urlKey, username) {
         let url = document.body.dataset[urlKey];
         if (username) {
-            url += "?username=" + encodeURIComponent(username);
+            url += `?username=${encodeURIComponent(username)}`;
         }
         return fetch(url);
     }
@@ -121,7 +121,7 @@ class WebAuthnHandler {
         }
 
         if (!registrationFinishResponse.ok) {
-            throw new Error("Registration failed with HTTP status code " + registrationFinishResponse.status);
+            throw new Error(`Registration failed with HTTP status code ${registrationFinishResponse.status}`);
         }
 
         const jsonData = await registrationFinishResponse.json();
@@ -192,7 +192,7 @@ class WebAuthnHandler {
         }
 
         if (!loginFinishResponse.ok) {
-            throw new Error("Login failed with HTTP status code " + loginFinishResponse.status);
+            throw new Error(`Login failed with HTTP status code ${loginFinishResponse.status}`);
         }
 
         window.location.reload();