let startDate = null;
let endDate = null;
// в updateInput добавь
for (let i = 0; i < monthDetails.length; i++) {
if (monthDetails[i].month === 0) {
if (monthDetails[i].date.toString() === cell_date) {
// для проверки рейнджа
if (!startDate || (startDate && endDate)) {
// На первый клик или новый рейндж
clearSelection();
startDate = monthDetails[i].timestamp;
cell.classList.add("isSelected");
} else {
// Второй клик
endDate = monthDetails[i].timestamp;
highlightRange();
}
}
}
}
//хелперы
const clearSelection = () => {
startDate = null;
endDate = null;
document.querySelectorAll(".cell_wrapper").forEach(cell => {
cell.classList.remove("isSelected", "inRange");
});
};
const highlightRange = () => {
if (startDate > endDate) {
[startDate, endDate] = [endDate, startDate];
}
document.querySelectorAll(".cell_wrapper").forEach(cell => {
if (cell.classList.contains("current")) {
const cellDate = new Date(year, month, parseInt(cell.textContent)).getTime();
if (cellDate === startDate || cellDate === endDate) {
cell.classList.add("isSelected");
} else if (cellDate > startDate && cellDate < endDate) {
cell.classList.add("inRange");
}
}
});
};
.cell_wrapper.inRange {
background-color: #f0f0f0;
color: #272727;
}
.cell_wrapper.current.inRange {
background-color: #e0e0e0;
border-radius: 0;
}
.cell_wrapper.isSelected {
border-radius: 50%;
background-color: #272727;
color: #fff;
}
handleStart = (event) => {
event?.stopPropagation();
const startTime = Date.now();
const { min, sec } = this.state;
this.setState({
isCounting: true,
startTime,
remainingTime: min * 60 + sec
});
this.counterID = setInterval(() => {
const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
const remainingTime = Math.max(0, this.state.remainingTime - elapsedTime);
const newMin = Math.floor(remainingTime / 60);
const newSec = remainingTime % 60;
this.setState({ min: newMin, sec: newSec });
if (remainingTime === 0) {
this.handlePause();
this.props.onCheckBoxClick();
}
}, 1000);
};