Skip to content

Commit

Permalink
Fix auto-update issue after date selection
Browse files Browse the repository at this point in the history
  • Loading branch information
Valik3201 committed Nov 22, 2023
1 parent c212678 commit 4eff573
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/js/02-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ resetBtn.disabled = true;

let endDate;
let intervalId;
let selectedDate;

const options = {
enableTime: true,
Expand All @@ -27,7 +28,7 @@ const options = {
minuteIncrement: 1,
onClose(selectedDates) {
if (selectedDates.length > 0) {
const selectedDate = selectedDates[0];
selectedDate = selectedDates[0];

if (selectedDate > new Date()) {
startBtn.disabled = false;
Expand All @@ -44,7 +45,7 @@ const options = {

Notiflix.Notify.success(`Selected Date: ${formattedDate}`);

endDate = selectedDate.getTime();
// endDate = selectedDate.getTime();
} else {
startBtn.disabled = true;
resetBtn.disabled = true;
Expand Down Expand Up @@ -112,6 +113,8 @@ function updateCountdown() {
}

startBtn.addEventListener("click", function () {
endDate = selectedDate.getTime();

intervalId = setInterval(updateCountdown, 1000);

startBtn.disabled = true;
Expand All @@ -129,6 +132,4 @@ resetBtn.addEventListener("click", function () {
document.querySelector("[data-hours]").textContent = "00";
document.querySelector("[data-minutes]").textContent = "00";
document.querySelector("[data-seconds]").textContent = "00";

endDate = undefined; // Reset endDate value
});

0 comments on commit 4eff573

Please sign in to comment.