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");