#6555 refactor to js #28

Merged
jorgep merged 13 commits from 6555-refactorToJs into test 2024-10-10 13:51:47 +00:00
1 changed files with 9 additions and 8 deletions
Showing only changes of commit 5e1a5f313a - Show all commits

View File

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