Skip to content

Commit 831fe75

Browse files
committed
[PRAC/cont] Fix incorrect highlight "new" cls/row
Correct logic of moving/viewing area on "newly" added client/last row. Worth noting: - using Map() method. core: B-3 / JS-BL
1 parent 735a719 commit 831fe75

File tree

1 file changed

+29
-20
lines changed
  • core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js

1 file changed

+29
-20
lines changed

core-courses/3-js-basic-level/practicum-js-basic-level/sb-crm-client/js/index.js

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2758,29 +2758,38 @@
27582758
}
27592759

27602760
const lastNewTableRow = outTableBody.lastElementChild; // фиксация последней строки
2761-
const defaultRowCellColors = []; // для цветов
2761+
if (!lastNewTableRow) return; // нет строки.. возврат
27622762

2763-
if (lastNewTableRow) {
2764-
// перемещение к "новому" клиенту/к последней строке таблицы
2765-
lastNewTableRow.scrollIntoView({
2766-
behavior: 'smooth',
2767-
block: 'center',
2768-
});
2763+
// кого предстоит перекрасить/выделить
2764+
const highlightClasses = [
2765+
'crm__output-table-body-cell_fio',
2766+
'crm__output-table-body-cell_crt-d-time',
2767+
'crm__output-table-body-cell_chg-d-time',
2768+
];
2769+
2770+
const defaultColorsMap = new Map(); // хранение исходных цветов/красок
2771+
2772+
// перемещение к "новому" клиенту/к последней строке таблицы
2773+
lastNewTableRow.scrollIntoView({
2774+
behavior: 'smooth',
2775+
block: 'center',
2776+
});
27692777

2770-
// изменение цвета/выделение строки
2771-
lastNewTableRow.querySelectorAll('td').forEach((td) => {
2772-
defaultRowCellColors.push(td.style.color);
2773-
td.style.fontWeight = '500';
2778+
// изменение цвета/выделение строки
2779+
lastNewTableRow.querySelectorAll('td').forEach((td) => {
2780+
if (highlightClasses.some((cls) => td.classList.contains(cls))) {
2781+
defaultColorsMap.set(td, td.style.color); // сохранение default цвета
2782+
td.style.fontWeight = 'bold';
27742783
td.style.color = '#7458c2'; // --cold-purple
2775-
});
2784+
}
2785+
});
27762786

2777-
// возврат к default цвету, через несколько секунды
2778-
setTimeout(() => {
2779-
lastNewTableRow.querySelectorAll('td').forEach((td, index) => {
2780-
td.style.fontWeight = 'normal';
2781-
td.style.color = defaultRowCellColors[index];
2782-
});
2783-
}, 2000);
2784-
}
2787+
// возврат к default цвету, через несколько секунды
2788+
setTimeout(() => {
2789+
defaultColorsMap.forEach((color, td) => {
2790+
td.style.fontWeight = 'normal';
2791+
td.style.color = color;
2792+
});
2793+
}, 2000);
27852794
}
27862795
})();

0 commit comments

Comments
 (0)