From 5e1a5f313a8da6c341e7c9352bdc3a24c3c6a011 Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 19 Jun 2024 13:18:43 +0200 Subject: [PATCH] refactor: refs #6555 check if is Empty --- js/clockIn.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/js/clockIn.js b/js/clockIn.js index 9e0ac05..5552db3 100644 --- a/js/clockIn.js +++ b/js/clockIn.js @@ -91,11 +91,11 @@ function printTimetable(timetable) { const liTotals = createElement("li", {}); timetable.forEach((row, index) => { for (let day = weekDays.length - 1; day >= 0; day--) { - const img = createElement("img", { attrs: { src: ifIsEmptyImage(row[`${day}daysAgoDirection`]) } }); - const p = createElement("p", { text: ifIsEmptyText(row[`${day}daysAgo`]) }); + const img = createElement("img", { attrs: { src: isEmpty(row[`${day}daysAgoDirection`], "image") } }); + const p = createElement("p", { text: isEmpty(row[`${day}daysAgo`], "text") }); const innerDiv = createElement("div", { childs: [img, p] }); - const outerDiv = createElement("div", { classes: ["time", ifIsEmpty(row[`${day}daysAgo`])], childs: [innerDiv] }); + const outerDiv = createElement("div", { classes: ["time", isEmpty(row[`${day}daysAgo`])], childs: [innerDiv] }); liContent.append(outerDiv); if (index === 0) { @@ -112,11 +112,12 @@ function printTimetable(timetable) { timetableList.append(table); } -const ifIsEmpty = (value) => (value?.trim() ? "show" : "hide"); - -const ifIsEmptyImage = (value) => (value?.trim() ? `img/${value}.svg` : "img/in.svg"); - -const ifIsEmptyText = (value) => (value?.toString()?.trim() ? value : "00:00"); +const isEmpty = (value, type) => { + const val = value?.toString()?.trim(); + if (!type) return val ? "show" : "hide"; + if (type === "image") return val ? `img/${val}.svg` : "img/in.svg"; + if (type === "text") return val ? val : "00:00"; +}; function close() { localStorage.removeItem("userData");