Merge pull request #802 from twetech/update-timer-when-pending

Time tracking paused when pending
This commit is contained in:
Johnny
2023-11-13 23:29:15 -05:00
committed by GitHub

View File

@@ -115,6 +115,16 @@
} }
} }
// Function to check status and pause timer
function checkStatusAndPauseTimer() {
var status = document.querySelector('select[name="status"]').value;
if (status.includes("Pending")) {
pauseTimer();
}
}
document.getElementById("hours").addEventListener('change', updateTimeFromInput); document.getElementById("hours").addEventListener('change', updateTimeFromInput);
document.getElementById("minutes").addEventListener('change', updateTimeFromInput); document.getElementById("minutes").addEventListener('change', updateTimeFromInput);
document.getElementById("seconds").addEventListener('change', updateTimeFromInput); document.getElementById("seconds").addEventListener('change', updateTimeFromInput);
@@ -124,6 +134,9 @@
document.getElementById("minutes").addEventListener('focus', handleInputFocus); document.getElementById("minutes").addEventListener('focus', handleInputFocus);
document.getElementById("seconds").addEventListener('focus', handleInputFocus); document.getElementById("seconds").addEventListener('focus', handleInputFocus);
document.querySelector('select[name="status"]').addEventListener('change', checkStatusAndPauseTimer);
document.getElementById("startStopTimer").addEventListener('click', function() { document.getElementById("startStopTimer").addEventListener('click', function() {
if (timerInterval === null) { if (timerInterval === null) {
startTimer(); startTimer();
@@ -144,12 +157,13 @@
try { try {
displayTime(); displayTime();
if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) { if (!localStorage.getItem(getLocalStorageKey("startTime")) && !localStorage.getItem(getLocalStorageKey("pausedTime"))) {
// If first time, start the timer automatically
startTimer(); startTimer();
} else if (localStorage.getItem(getLocalStorageKey("startTime"))) { } else if (localStorage.getItem(getLocalStorageKey("startTime"))) {
// Continue timer if it was running before
startTimer(); startTimer();
} }
// Check and pause timer if status is pending
checkStatusAndPauseTimer();
} catch (error) { } catch (error) {
console.error("There was an issue initializing the timer:", error); console.error("There was an issue initializing the timer:", error);
} }