Still needs some tweaks and cleanup but I think it’s passable.
Any feedback is welcome. Think the colors should be tweaked? I want to know what you would do!
Code is ugly and sloppy? Point it out! I don’t mind if the feedback sounds harsh.
If anyone feels like reading, below I will talk/rant about some issues I’ve run into with the timer and progress bar. I don’t think I really need to be concerned about them because of how rare they seem to be but I thought I’d see if anyone had any insights.
To get an accurate timer I first subtract the start time from the time right now in milliseconds. It then divides by 1000 to get seconds that are decimal numbers which I then use Math.floor() on.
const TIME_LEFT = timerLength - Math.floor((Date.now() - START) / 1000);
On the rare occasion I will get two of the same numbers in a row, like 34 seconds and on the next tick 34 again, but then it will get back on track and next tick will be 32.
If I console log the number, without applying Math.floor(), I see this happens when the first number is something like 34.001 and then the second is something like 34.999.
console.log((Date.now() - START) / 1000);
Whenever I’m on the tab of my pomodoro the logged numbers are always 34, 35.001, 36.003, 37.002 for example.
When I switch tabs or load a new website on a tab the decimal portion will jump from between .1xx to .9xx but stay consistent after the jump and returns to the lower range (34.002) when the web page tab is reselected.
The repeating digits happen very rarely and I’m not sure it has anything to do with the decimal part of the number changing when switching tabs. I can’t seem to recreate the issue consistently.
The other random bug I’ve seen that’s even more rare is sometimes, I think the second if statement of the updateProgressBar() function,
if (timeLeft == 0), never evaluates and that causes the circle progress bar not to reset.
It’s kind of a gamble to reproduce the first issue and the second one I can’t seem to reproduce.
I thought I could solve the first with Math.round() but when I switch tabs it would round the number up and I would get a duplicate number from Math.round(13.94) and then Math.round(14.076) using the above picture as an example.
I suppose using Math.round() would solve the issue of rare duplicate numbers when tab has focus. I’ll have to see.
If anyone has any thoughts I’m all ears.